Fortran 到 C 库的链接器错误 - /usr/lib/libf2c.so:对“MAIN__”的未定义引用
所以我在使用 fortran 到 C 库时遇到了一些麻烦。现在,在讨论这个问题之前,我可以告诉你,我不能像某些论坛网站所建议的那样使用 g2c。
现在,解决问题。当我尝试编译一个非常大的项目时,我得到以下信息:
[from the makefile...] g++ -L [~200 dirs] -l [~200 libs] -lf2c
/usr/lib/libf2c.so: undefined reference to 'MAIN__'
collect2: ld returned 1 exit status
make: *** [all] Error 1
现在,我检查了我的 /usr/lib
目录并得出以下结果:
$ locate libf2c
/usr/lib/libf2c.so
/usr/lib/libf2c.so.0
/usr/lib/libf2c.so.0.22
所以至少,它在那里。我使用了谷歌,它告诉我输入...
sudo rm /usr/lib/libf2c.so && sudo ln -s /usr/lib/libf2c.a /usr/lib/libf2c.so
...会有帮助。关于库的陈旧性意味着 gcc 不再正确链接到它,并试图找到一个没有的 main 方法。所以我就这么做了。但是,在我链接到 .a 库后,g++ 现在根本找不到该库。
g++ -L [~200 dirs] -l [~200 libs] -lf2c
/usr/bin/ld: cannot find -lf2c
collect2: ld returned 1 exit status
make: *** [all] Error 1
所以实际上我已经倒退了。有人对我应该从这里去哪里有任何想法吗?
编辑:所以我想我已经明白了。我按照这个重新安装库。现在它神奇地不再抱怨 fortran main 不存在。谢谢你们的帮助。
So I'm having a little trouble with the fortran to C library. Now, before I get into the problem, I can tell you that I cannot use g2c as some forum sites have suggested.
Now, to the problem. When I try to compile a very large project, I get the following:
[from the makefile...] g++ -L [~200 dirs] -l [~200 libs] -lf2c
/usr/lib/libf2c.so: undefined reference to 'MAIN__'
collect2: ld returned 1 exit status
make: *** [all] Error 1
Now, I have checked my /usr/lib
directory and have come up with the following:
$ locate libf2c
/usr/lib/libf2c.so
/usr/lib/libf2c.so.0
/usr/lib/libf2c.so.0.22
So at the very least, it is there. I used the google, which told me that entering...
sudo rm /usr/lib/libf2c.so && sudo ln -s /usr/lib/libf2c.a /usr/lib/libf2c.so
...would help. Something about the oldness of the library meaning that gcc doesn't link to it right anymore, and tries to find a main method where there isn't one. So I did it. However, after I linked to the .a library, g++ now can't find the library at all.
g++ -L [~200 dirs] -l [~200 libs] -lf2c
/usr/bin/ld: cannot find -lf2c
collect2: ld returned 1 exit status
make: *** [all] Error 1
So in effect I've gone backwards. Anyone have any ideas as to where I should go from here?
EDIT: So I think I figured it out. I followed this to reinstall the libs. Now it magically does not complain that the fortran main doesn't exist. Thanks for your help guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该更加注意第一条错误消息。链接器告诉您找不到符号
MAIN__
,这正是 f2c 预期 Fortran main 将在您的 C 或 C++ 代码中编译到的位置。 f2c 库本身运行得很好。原始错误的解决方案是确保在代码中定义了正确的入口点。可能是通过使用 C++ 进行编译时,您会遇到名称修改问题,并且 f2c 库的正确入口点不存在。
现在,通过摆弄 f2c 库,您已经完全破坏了 f2c 安装。重新安装并重新开始...
You should have paid closer attention to the first error message. The linker is telling you that no symbol
MAIN__
can be found, which is what f2c is expected that the fortran main will be compiled to in your C or C++ code somewhere. The f2c library itself was working just fine.The solution to the original error would be to make sure the correct entry point is defined in your code. It might be that by using C++ to compile, you have name mangling problems and the correct entry point for the f2c library doesn't exist.
Now by messing around with the f2c libraries, you have totally broken your f2c installation. Reinstall it and start again...
好吧,
将删除
/usr/lib/libf2c.so
,因此您会收到新错误。因此,至少您必须重新安装该库并链接到新版本,然后查看您所在的位置。
Well,
will delete
/usr/lib/libf2c.so
, hence the new error you're getting.So as a minimum you'll have to reinstall that library and link to the new version, and then see where you are.
我知道这是一个旧线程,但当我遇到同样的问题时,它对我很有帮助。
我通过应用命令解决了这个问题:
sudo rm /usr/lib/libf2c.so && sudo ln -s /usr/lib/libf2c.a /usr/lib/libf2c.so
正如OP所做的那样。我在这里发现了同样的技巧:
http://byeworld。 blogspot.com/2009/01/libf2cso-undefined-reference-to-main.html
它所做的实际上是删除动态库并创建静态库的别名。它对OP不起作用的原因是他/她没有安装静态库。从 LOCATE 命令的输出可以清楚地看出这一点。
我希望这对其他人有帮助。
I know it's an old thread, but It was helpful for me when I faced the same problem.
I solved it by applying the commands:
sudo rm /usr/lib/libf2c.so && sudo ln -s /usr/lib/libf2c.a /usr/lib/libf2c.so
as the OP did. I found the same trick here:
http://byeworld.blogspot.com/2009/01/libf2cso-undefined-reference-to-main.html
What it does is in fact is to delete the dynamic library and create an alias to the static library. The reason why it didn't work for the OP was that he/she didn't have the static library installed. That was clear from the output of the LOCATE command.
I hope this helps someone else.