c - trouble compiling against static library -
i have created static library, libstuff.a, gcc , ar. i've installed library in /custom/lib/dir/ , header files in /custom/include/dir/. when try compile application against archive, running issues.
the application trying compile uses gcc -l/custom/lib/dir/ -i/custom/include/dir/ -lstuff.
when attempt compile, error function declare in stuff.h , define in stuff.c.
main.c:51: undefined reference `stuff_init' collect2: error: ld returned 1 exit status if remove libstuff.a /custom/lib/dir/ compiler complains /usr/bin/ld: cannot find -lstuff. if put back, doen't complain. it's finding archive correctly.
if remove line of code #include "stuff.h" main.c gcc complains stuff_init being undefined, it's finding headers correctly.
if run nm libstuff.a, output includes 0000000000000000 t stuff_init. function defined in archive file.
so doing wrong?
you don't show exact linking line, chances should (but don't) list libraries after object files:
gcc -o program main.o -l/custom/lib/dir -lstuff if there's more 1 object file outside of libraries, list them before of libraries. -l options may go anywhere before -llib option uses library given directory.
Comments
Post a Comment