Linker 未定义引用,将Plplot与GFortran链接时出错

Linker 未定义引用,将Plplot与GFortran链接时出错,linker,fortran,linker-errors,gfortran,Linker,Fortran,Linker Errors,Gfortran,我试图编译以下在中找到的Fortran代码 我尝试编译程序时使用了以下命令: 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:(

我试图编译以下在中找到的Fortran代码

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

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

您缺少外部引用

开始:

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


我想您也应该这样做。

您显示给我们的错误消息是由链接器生成的,而不是由编译器生成的。我不知道gfortran,所以下面的内容可能有点离题

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

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

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

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

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

我也将此发布在ubuntuforums上。用户gmargo提供以下解决方案:

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

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

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

您的源链接已断开,无法说明明显的问题,但我已经安装了库。@rmtatum下次请尝试提供所有相关信息。因此,根据手册页,您不会得到明显的建议。它应该有效:@rmtatum:也许应该ork,但它不是。我现在已经阅读了一些gcc的手册页,不相信您在编译命令中提供了正确的链接语句。如果您只阅读了gfortran的手册页,那么您就错过了很多故事——它们只记录了gfortran在gcc其余部分之外提供的内容。继续阅读。使用您建议的命令(我在阅读您的文章之前尝试过该命令),产生了以下错误:/usr/bin/ld:not find-lplplot collect2:ld返回1退出状态
gfortran testplot2d.f90 -o testplot2d $(pkg-config --cflags --libs plplotd-f95)