F77:使用 g77 编译通常使用 Absoft 编译器编译的程序时出现问题
我不是 Fortran 程序员(只是短暂的经验),但我需要编译部分用 F77
编写的程序。在我之前有人用 Absoft
编译器编译过它,但现在我需要在另一台机器上使用 g77
重复该过程。对于 Absoft,makefile 已将
f77 -f -w -O -B100 -B108 -c *.f
mv *.f flib && mv *.o olib
f77 -B100 -o runme olib/*.o clib/*.o -L/usr/X11R6/lib64 -L/usr/X11R6/lib -lX11 -L$PVM_ROOT/lib/$PVM_ARCH -lfpvm3 -lpvm3 -L$ABSOFT/lib -lU77
这些行修改为
g77 -w -O -B100 -B108 -c *.f
mv *.f flib && mv *.o olib
g77 -B100 -o runme olib/*.o clib/*.o -L/usr/X11R6/lib64 -L/usr/X11R6/lib -lX11 -L$PVM_ROOT/lib/$PVM_ARCH -lfpvm3 -lpvm3 -lgfortran -lgfortranbegin
但我收到以下错误消息
somefile.f:(.text+0x93): undefined reference to `for_open'
somefile.f:(.text+0xf4): undefined reference to `for_write_seq_fmt'
somefile.f:(.text+0x128): undefined reference to `for_write_seq_fmt_xmit'
somefile.f:(.text+0x454): undefined reference to `for_read_seq'
如何解决此问题?
UPDATE1
如果我将 -libifcore
添加到最后一行(链接器)的末尾,那么我发现
/usr/bin/ld: cannot find -libifcore
我已经找到了该库
$ find /opt/intel/* -name 'libifcore*'
/opt/intel/fce/9.1.036/lib/libifcore.a
/opt/intel/fce/9.1.036/lib/libifcore.so
/opt/intel/fce/9.1.036/lib/libifcore.so.5
/opt/intel/fce/9.1.036/lib/libifcore_pic.a
/opt/intel/fce/9.1.036/lib/libifcoremt.a
/opt/intel/fce/9.1.036/lib/libifcoremt.so
/opt/intel/fce/9.1.036/lib/libifcoremt.so.5
/opt/intel/fce/9.1.036/lib/libifcoremt_pic.a
但是即使我在源目录中执行以下操作
$ export PATH=$PATH:/opt/intel/fce/9.1.036/lib/
$ ln -s /opt/intel/fce/9.1.036/lib/libifcore.so
没有找到。
此外,这也是我遇到另一个问题的同一台机器 如何将-libm传递给MPICC? libimf.so:警告:feupdateenv未实现并且总是会失败
似乎编译器应该找到该库(如果需要)
$ echo $LD_LIBRARY_PATH
/opt/intel/fce/9.1.036/lib:/opt/intel/cce/9.1.042/lib:/usr/local/lib/openmpi:/usr/local/lib:/usr/lib:
I am not a Fortran programmer (just a short experience), but I need to compile a program partly written in F77
. Someone has compiled it with Absoft
compiler before me, but now I need to repeat the procedure on another machine with g77
. For Absoft, the makefile has
f77 -f -w -O -B100 -B108 -c *.f
mv *.f flib && mv *.o olib
f77 -B100 -o runme olib/*.o clib/*.o -L/usr/X11R6/lib64 -L/usr/X11R6/lib -lX11 -L$PVM_ROOT/lib/$PVM_ARCH -lfpvm3 -lpvm3 -L$ABSOFT/lib -lU77
I have modified these lines to be
g77 -w -O -B100 -B108 -c *.f
mv *.f flib && mv *.o olib
g77 -B100 -o runme olib/*.o clib/*.o -L/usr/X11R6/lib64 -L/usr/X11R6/lib -lX11 -L$PVM_ROOT/lib/$PVM_ARCH -lfpvm3 -lpvm3 -lgfortran -lgfortranbegin
But I get the following error messages
somefile.f:(.text+0x93): undefined reference to `for_open'
somefile.f:(.text+0xf4): undefined reference to `for_write_seq_fmt'
somefile.f:(.text+0x128): undefined reference to `for_write_seq_fmt_xmit'
somefile.f:(.text+0x454): undefined reference to `for_read_seq'
How can I fix this?
UPDATE1
If I add -libifcore
to the end of the last line (linker), then I get
/usr/bin/ld: cannot find -libifcore
I have located the library
$ find /opt/intel/* -name 'libifcore*'
/opt/intel/fce/9.1.036/lib/libifcore.a
/opt/intel/fce/9.1.036/lib/libifcore.so
/opt/intel/fce/9.1.036/lib/libifcore.so.5
/opt/intel/fce/9.1.036/lib/libifcore_pic.a
/opt/intel/fce/9.1.036/lib/libifcoremt.a
/opt/intel/fce/9.1.036/lib/libifcoremt.so
/opt/intel/fce/9.1.036/lib/libifcoremt.so.5
/opt/intel/fce/9.1.036/lib/libifcoremt_pic.a
But even if I do the following in the source directory
$ export PATH=$PATH:/opt/intel/fce/9.1.036/lib/
$ ln -s /opt/intel/fce/9.1.036/lib/libifcore.so
it is not found.
Moreover, it is the same machine where I get another problem How to pass -libm to MPICC? libimf.so: warning: feupdateenv is not implemented and will always fail
It seems that the compiler should find the library, if needed
$ echo $LD_LIBRARY_PATH
/opt/intel/fce/9.1.036/lib:/opt/intel/cce/9.1.042/lib:/usr/local/lib/openmpi:/usr/local/lib:/usr/lib:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Absoft 接受的 Fortran 77 扩展版本与 g77 接受的 Fortran 77 扩展版本不完全兼容。
因此,不能保证您无需编辑代码就可以做到这一点。我似乎记得 Absoft 编译器接受了一种不能用 g77 复制的方便的初始化语法。
Absoft accepted an extended version of Fortran 77 that is not completely compatible with the extended version of Fortran 77 accepted by g77.
So there is no guarantee that you can do this without editing the code. I seem to recall that the Absoft compiler accepted a handy initialization syntax that can not be replicated with g77.
如果你想编译&使用g77进行链接,最简单的方法是使用命令“g77”。 (f77 在您的计算机上调用什么编译器?尝试“f77 -v”或类似的命令来找出答案...)它应该自动找到 g77 Fortran 特定的库。您不需要显式链接到 Fortran 库,尤其是 gfortran 的库,因为 gfortran 是一个不同的编译器。您还可以编译&与 gfortran 链接——它可能会识别源代码是 Fortran 77,并且如果文件具有正确的文件类型,则可以正确编译,否则您将不得不使用选项——对于此编译器,请使用命令“gfortran”。
对于 g77 和 gfortran,它不需要 Intel 库——也许 f77 已连接到您计算机上的 ifort(Intel 编译器)?
稍后编辑:
我建议首先尝试一些更简单的方法来测试您的设置。
尝试将此 FORTRAN 77 程序作为文件“junk.f”
尝试此命令:
g77 junk.f -o junk.exe
通过以下方式运行:
./junk.exe
这将测试 g77 是否正常工作。
If you want to compile & link using g77, the easiest way is to use the command "g77". (What compiler does f77 invoke on your computer? Try "f77 -v" or similar to find out...) It should automatically find the g77 Fortran-specific libraries. You should not need to explicitly link to Fortran libraries, and especially not to the libraries of gfortran, which is a different compiler. You could also compile & link with gfortran -- it will probably recognize that the source code is Fortran 77 and compile appropriately if the files have the correct file type, otherwise you will have to use options -- for this compiler, use the command "gfortran".
With g77 and gfortran it should not need Intel libraries -- maybe f77 is connected to ifort, the Intel compiler, on your computer?
Edited later:
I suggest trying something simpler first to test your setup.
Try this FORTRAN 77 program as file "junk.f"
Try this command:
g77 junk.f -o junk.exe
Run it via:
./junk.exe
This will test whether g77 is working.
您似乎正在尝试与 libifcore 链接。
编辑:
您可以通过添加来包含此库
'-lifcore' 添加到您的编译器选项中。引用 gcc 教程
it looks like you are trying to link with
libifcore
.Edit:
You can include this library by adding
'-lifcore' to your compiler options. To quote the gcc tutorial
为什么使用 g77 而不是 gfortran?
多处理是什么意思? openmp 还是矢量化?
您可以将 openmp 与 gfortran 编译器一起使用,当您想像 ifort 编译器一样使用向量模式时,您必须在编译器选项中显式指定 sse。
why do you use g77 and not gfortran?
what do you mean with multiprocessing? openmp or vectorized?
you can use openmp with the gfortran compiler and when you want to use vector mode like the ifort compiler does, you have to specify sse explicitly in the compiler options.
看来问题出在其中一个源文件中的错误,这对于 Absoft 编译器来说并不是什么大问题。 g77 给出了有关它的警告,但编译此文件并在没有二进制文件的情况下产生原始错误(问题中提到)。
当我尝试 ifort 时,该文件的编译被中止,但其他文件被编译并创建了一个二进制文件。
当我删除多余的逗号时,两个编译器都编译了所有内容并创建了二进制文件,尽管 ifort 产生了许多警告。
然后,当我尝试运行这两个二进制文件时,Intel 编译器制作的二进制文件工作正常,但 g77 制作的二进制文件表现得很奇怪,并没有真正做到我想要的。
现在原来的问题已经解决了,但是代码不能在多处理模式下运行,因此不幸的是二进制文件对我来说毫无用处。
It seems that the problem was in an error in one of the source files, which wasn't a big deal for Absoft compiler.
g77
was giving a warning about it, but compiling this file and producing the original errors (mentioned in the question) without a binary.When I tried
ifort
, compilation of that file was aborted, but other files were compiled and a binary was created.When I removed the extra comma, then both compilers have compiled everything and created binaries, although
ifort
produced a number of warnings.Then, when I tried to run both binaries, the one made by Intel comiler was working fine, but the one by
g77
was behaving very strange and didn't really do what I wanted.So now the original problem is resolved, however the code doesn't run in multiprocessing mode, so the binary is unfortunately useless for me.