Trying to include a library, but keep getting 'undefined reference to' messages

前端 未结 3 2229
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 07:18

I am attempting to use the libtommath library. I\'m using the NetBeans IDE for my project on Ubuntu linux. I have downloaded and built the library, I have done a \'make inst

相关标签:
3条回答
  • 2020-12-02 07:24

    If the .c source files are converted .cpp (like as in parsec), then the extern needs to be followed by "C" as in

    extern "C" void foo();
    
    0 讨论(0)
  • 2020-12-02 07:35

    The trick here is to put the library AFTER the module you are compiling. The problem is a reference thing. The linker resolves references in order, so when the library is BEFORE the module being compiled, the linker gets confused and does not think that any of the functions in the library are needed. By putting the library AFTER the module, the references to the library in the module are resolved by the linker.

    0 讨论(0)
  • 2020-12-02 07:36

    Yes, It is required to add libraries after the source files/objects files. This command will solve the problem:

    gcc -static -L/usr/lib -I/usr/lib main.c -ltommath
    
    0 讨论(0)
提交回复
热议问题