CentOS 7 安装 pgplot

CentOS在执行程序时,出现如下的报错

CentOS 7 安装 pgplot_第1张图片

显然是因为没有cpgplot.h,需要安装pgplot

以下安装步骤参考

https://blog.csdn.net/sinat_34850075/article/details/77017025

https://community.dur.ac.uk/physics.astrolab/ppgplot.html

1.下载pgplot

wget ftp://ftp.astro.caltech.edu/pub/pgplot/pgplot5.2.tar.gz

2.移动.gz文件到/usr/local/src文件夹下解压,并且在/usr/local/下建立文件夹pgplot,并且cd进此文件夹,这个是安装文件夹。

mv pgplot5.2.tar.gz /usr/local/src/
tar -zxvf pgplot5.2.tar.gz
mkdir /usr/local/pgplot/
cd /usr/local/pgplot/

3.移动drivers.list,并编辑此文件

cp /usr/local/src/pgplot/drivers.list .
vi drivers.list

drivers.list文件里面选取这几个,把这几行前面的!去掉就可以了.

  GIDRIV 1 /GIF GIF-format file, landscape
  GIDRIV 2 /VGIF GIF-format file, portrait
  NUDRIV 0 /NULL Null device (no output) Std F77
  PSDRIV 1 /PS PostScript printers, monochrome, landscape Std F77
  PSDRIV 2 /VPS Postscript printers, monochrome, portrait Std F77
  PSDRIV 3 /CPS PostScript printers, color, landscape Std F77
  PSDRIV 4 /VCPS PostScript printers, color, portrait Std F77
  XWDRIV 1 /XWINDOW Workstations running X Window System C
  XWDRIV 2 /XSERVE Persistent window on X Window System C

参考  http://server.zol.com.cn/127/1270916.html

4.确认X11已经安装

sudo yum install libX11 libX11-devel
sudo yum install xorg-x11-drivers.x86_64

 5.更改文件

cd /usr/local/src/pgplot/src
sudo cp grpckg1.inc grpckg1.inc.backup
sudo cp pgplot.inc pgplot.inc.backup
sudo vim grpckg1.inc
sudo vim pgplot.inc

先备份,再更改

emacs grpckg1.inc & # Replace " PARAMETER (GRIMAX = 8) " in line 29
                    #    by   " PARAMETER (GRIMAX = 32) "
                    
emacs pgplot.inc &  # Replace " PARAMETER (PGMAXD=8) " in line 7
                    #    by   " PARAMETER (PGMAXD=32) " 

6.编译安装

cd /usr/local/pgplot/
sudo /usr/local/src/pgplot/makemake /usr/local/src/pgplot linux g77_gcc

重新执行编译安装/usr/local/src/pgplot/makemake /usr/local/src/pgplot linux g77_gcc

 执行完毕之后会出现如下的文件

drivers.list   grexec.f   grpckg1.inc   makefile   pgplot.inc   rgb.txt

# If you are using the gcc 4.0 (or above) compilers (i.e. gfortran instead
# of g77), perform the following:

emacs makefile & # Replace "FCOMPL=g77"       in line 25 
                 #   by    "FCOMPL=gfortran" 
                 # 
                 # Replace "FFLAGC=-u -Wall -fPIC -O" in line 26
                 #   by    "FFLAGC=-ffixed-form -ffixed-line-length-none -u -Wall -fPIC -O"

https://blog.csdn.net/zhanghaizhe/article/details/72359244 

在Makefile中加入 LINUXWSLIBS   = -L/usr/include/X11/lib -lxview -lolgx -lX11 -lm -lf2c -lgfortran 

sudo make
sudo make cpg
sudo vim /usr/local/src/pgplot/makehtml
make pgplot.html
emacs /usr/local/src/pgplot/makehtml &	# this file needs to be edited to 
			  #  replace the first line by
			  # 	#!/usr/bin/perl

7. 建立库链接

cd /usr/local/lib
ln -s /usr/local/pgplot/libpgplot.a libpgplot.a
ln -s /usr/local/pgplot/libcpgplot.a libcpgplot.a
cp /usr/local/pgplot/libpgplot.so .
sudo vim /etc/ld.so.conf

emacs /etc/ld.so.conf &	  # edit this file to add the line /usr/local/lib

sudo /sbin/ldconfig -v

ln -s /usr/local/pgplot/cpgplot.h /usr/local/include/cpgplot.h

8. 最后需要在每个用户的.bash_profile中加入pgplot相关PGPLOT_DIR=/usr/local/pgplot/

如果环境变量没有设置,可以通过下属命令来设置:

$ export PGPLOT_DIR=/opt/local/lib
$ export PGPLOT_DEV=/Xserve

参考 http://shaoguangleo.github.io/2018/01/21/pgplot-installation/

9. 安装结束,可以在安装目录下运行pgdemo来测试是否可以运行

source /home/m/.bash_profile
cd /usr/local/pgplot
./pgdemo1

此时,会跳出如下信息:

Graphics device/type (? to see list, default /Xserve): ?
PGPLOT v5.2.2 Copyright 1997 California Institute of Technology
Interactive devices:
   /XWINDOW   (X window window@node:display.screen/xw)
   /XSERVE    (A /XWINDOW window that persists for re-use)
Non-interactive file formats:
   /GIF       (Graphics Interchange Format file, landscape orientation)
   /VGIF      (Graphics Interchange Format file, portrait orientation)
   /LATEX     (LaTeX picture environment)
   /NULL      (Null device, no output)
   /PNG       (Portable Network Graphics file)
   /TPNG      (Portable Network Graphics file - transparent background)
   /PS        (PostScript file, landscape orientation)
   /VPS       (PostScript file, portrait orientation)
   /CPS       (Colour PostScript file, landscape orientation)
   /VCPS      (Colour PostScript file, portrait orientation)
Graphics device/type (? to see list, default /Xserve):

我输入 :  Xserve

可以显示图像,证明安装成功!

参考了http://shaoguangleo.coding.me/2011/06/12/pgplot-cpgbeg/

--------------------------------------------------------------------------------------------------------

CentOS 7 安装 pgplot_第2张图片

 以上问题解决参考https://blog.csdn.net/imyang2007/article/details/8296331

使用gcc编译代码是报出

error: 'for' loop initial declarations are only allowed in C99 mode

note: use option -std=c99 or -std=gnu99 to compile your code

错误,这是因为在gcc中直接在for循环中初始化了增量:

    for(int i=0; i

这语法在gcc中是错误的,必须先先定义i变量:

    int i;
    for(i=0;i 这是因为gcc基于c89标准,换成C99标准就可以在for循环内定义i变量了:

gcc src.c -std=c99 -o src

你可能感兴趣的:(CentOS 7 安装 pgplot)