我尝试编译以下 Fortran 代码,该代码位于 http://techlogbook.wordpress.com/200...-kubuntu-8-04/
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 的手册页,并且我相信我正在使用正确的选项来链接库。)
最佳答案
您向我们展示的错误消息是由链接器生成的,而不是编译器生成的。我不了解 gfortran,所以接下来的内容可能离题
-I 通常(在我熟悉的 Linux 和 Unix 编译器上)标识一个目录,其中包含要包含在编译中(而不是链接时)的文件。对于 Fortran,编译模块时创建的 .mod
文件必须在编译期间包含在内。
由于您没有收到错误消息,告诉您未找到您使用
的模块,因此您可以在告诉编译器查找的位置找到该模块的基础上进行工作。
我熟悉的 Linux 编译器使用 -L 标志、目录和库名称的缩写形式来标识要链接的库。在你的情况下,我希望看到类似的内容:
-L/path/to/installed/lib/files -lplplot
包含在您的编译声明中。我不知道你如何告诉 gfortran 在链接时包含该库,但我在你的编译语句中没有看到任何内容告诉 gfortran 要链接哪些库。
关于linker - 未定义的引用,将 Plplot 与 GFortran 链接时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4370692/