3

我尝试编译在 http://techlogbook.wordpress.com/200...-kubuntu-8-04/找到的以下 Fortran 代码

program testplplot2d
use plplot
implicit none
real(plflt),dimension(6) :: x,y
real(plflt)::xmin,xmax,ymin,ymax
x=(/1,2,3,4,5,6/)
y=x**2
write(*,*) y
call plinit()
xmin=1.0
xmax=6.0
ymin=1.0
ymax=40.0
call plcol0(1)
call plenv(xmin,xmax,ymin,ymax,0,0)
call pllab('X','Y','Test 1D plot')
call plpoin(x,y,9)
call plline(x,y)
y=x**3
call plpoin(x,y,9)
call plline(x,y)
call plend()

end program testplplot2d

我在尝试编译程序时使用了以下命令:

gfortran -I/usr/lib/fortran/modules/plplot testplot2d.f90 -o testplot2d

但是我收到了下面详述的链接错误消息:

/tmp/cckSqEg4.o: In function `MAIN__':
testplot2d.f90:(.text+0x10c): undefined reference to `plinit_'
testplot2d.f90:(.text+0x154): undefined reference to `plcol0_'
testplot2d.f90:(.text+0x181): undefined reference to `plenv_'
testplot2d.f90:(.text+0x1a6): undefined reference to `__plplotp_MOD_pllab'
testplot2d.f90:(.text+0x248): undefined reference to `__plplot_MOD_plpoin'
testplot2d.f90:(.text+0x2e5): undefined reference to `__plplot_MOD_plline'
testplot2d.f90:(.text+0x3c6): undefined reference to `__plplot_MOD_plpoin'
testplot2d.f90:(.text+0x463): undefined reference to `__plplot_MOD_plline'
testplot2d.f90:(.text+0x46d): undefined reference to `plend_'
collect2: ld returned 1 exit status

我应该怎么做才能纠正这个问题?(我阅读了 gfortran 的手册页,并且我相信我使用了正确的选项来链接库。)

4

3 回答 3

2

您向我们展示的错误消息是由链接器生成的,而不是编译器。我不知道 gfortran,所以接下来的内容可能有点过分

-I 通常(在我熟悉的 Linux 和 Unix 编译器上)标识一个目录,该目录包含要包含在编译中的文件,而不是在链接时。Fortran.mod编译模块时创建的文件必须包含在编译期间。

由于您没有收到错误消息告诉您USE未找到该模块,因此您可以在您告诉编译器查找的位置找到它的基础上工作。

我熟悉的 Linux 编译器使用 -L 标志、目录和库名称的缩写形式来标识要链接的库。在你的情况下,我希望看到类似的东西:

-L/path/to/installed/lib/files -lplplot

包含在您的编译语句中。你如何告诉 gfortran 在链接时包含库我不知道,但我在你的编译语句中没有看到任何告诉 gfortran 要链接哪些库的内容。

于 2010-12-06T22:36:42.970 回答
1

我也在 ubuntuforums 上发布了这个。用户 gmargo发布了以下解决方案:

安装 libplplot-dev 包,然后使用以下命令行编译:

gfortran testplot2d.f90 -o testplot2d $(pkg-config --cflags --libs plplotd-f95)

感谢@belisarius 和@High-Performance-Mark 的努力。

于 2010-12-07T19:31:05.197 回答
0

您缺少外部参考。

获取代码的页面开始:

我从 Kubuntu Adept 包管理器安装了 libplplot,并选择了“libplplot-fortran9”包。

我想你也应该这样做。

于 2010-12-06T20:58:36.830 回答