linker - 未定义的引用,将 Plplot 与 GFortran 链接时出错

标签 linker fortran linker-errors gfortran

我尝试编译以下 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/

相关文章:

c++ - 如何使用 g++47 允许 -z multidefs

c - 在 x64 环境中与 GCC 和 x86 ASM 链接

javascript - 用于识别 Fortran 数字的正则表达式模式

fortran - NetCDF:开始+计数超出维度界限

fortran - 编译具有多个部分的 Fortran 程序

ios - 将库添加到 IOS 应用程序会导致可怕的构建失败

c++ - C++编译器问题: 3>cl : Command line error D8016: '/clr' and '/arch:SSE2' command-line options are incompatible

c++ - 使用 C++ header 的简单 C 程序中的链接错误

ios - native 链接失败, undefined symbol : _dispose_managed_object during deployment to an iOS device

c++ - 链接器不构造用户定义的类型