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

后端 未结 3 1597
心在旅途
心在旅途 2021-01-21 05:08

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.

相关标签:
3条回答
  • 2021-01-21 05:35

    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.

    0 讨论(0)
  • 2021-01-21 05:54

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

    0 讨论(0)
  • 2021-01-21 05:55

    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.

    0 讨论(0)
提交回复
热议问题