未定义的参考,错误链接Plplot与GFortran

时间:2010-12-06 20:35:32

标签: 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的手册页,我相信我正在使用正确的选项来链接库。)

3 个答案:

答案 0 :(得分:2)

您向我们展示的错误消息是由链接器而不是编译器生成的。我不知道gfortran所以接下来的内容可能是广泛的标记

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

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

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

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

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

答案 1 :(得分:1)

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

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

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

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

答案 2 :(得分:0)

您缺少外部参考。

The page from where you got the code开始:

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

我想你应该这样做。

相关问题