未定义的引用,错误链接Plplot与GFortran
我试图编译找到下面的Fortran代码在 http://techlogbook.wordpress.com/200...-kubuntu-8-04/未定义的引用,错误链接Plplot与GFortran
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的手册页,我相信我正在使用链接库的正确选项。)
我也在ubuntuforums上发布了这个。用户gmargo posted以下解决方案:
安装libplplot-dev软件包,然后用此命令行编译:
gfortran testplot2d.f90 -o testplot2d $(pkg-config --cflags --libs plplotd-f95)
谢谢@belisarius和@高性能唛的努力。
您缺少外部参考。
The page from where you got the code开始:
我安装Kubuntu的娴熟包管理器libplplot,并选择“libplplot-fortran9“包。
我想你应该这样做。
感谢您陈述明显,但我已经安装了库。 – rmtatum 2010-12-06 21:57:09
@rmtatum下次尝试提供所有相关信息。所以你不会得到_obvious_ suggestions – 2010-12-07 02:04:38
您向我们显示的错误消息是由链接器而不是编译器生成的。我不知道gfortran,所以后面的内容可能会很宽
- 我通常(在我熟悉的Linux和Unix编译器上)标识包含要包含在编译中的文件的目录,而不是链接时。对于Fortran,编译模块时创建的.mod
文件必须包含在编译期间。
由于您没有收到错误消息,告诉您找不到您找到USE
的模块,因此您可以在找到告警编译器的位置的基础上开展工作。
我熟悉的Linux编译器使用-L标志,目录和库名的缩写形式来标识要链接的库。在你的情况下,我希望看到类似于:
-L/path/to/installed/lib/files -lplplot
包括在您的编译声明中。你如何告诉gfortran在我不知道的链接时加入图书馆,但是我没有看到任何可以告诉gfortran链接哪些图书馆的编译声明。
您的源代码的链接已中断 – 2010-12-06 20:55:31