Linker errors with Fortran to C library - /usr/lib/libf2c.so: undefined reference to 'MAIN__'

北城余情 提交于 2019-12-01 21:33:40

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...

Well,

sudo rm /usr/lib/libf2c.so && sudo ln -s /usr/lib/libf2c.a /usr/lib/libf2c.so

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!