0

I got a very weird observation of gcc:

Assume we have a library liblolo.a and we have a test program test_lolo.c which uses a function of liblolo.a called lolo_add2 (doesn't matter the function at all).

I first created an object file out of test_lolo.c:

$ gcc -c -o test_lolo.o test_lolo.c

The weird observation is that linking in this style works:

$ gcc test_lolo.o -L./ -llolo -o static_app

But this line does not work:

$ gcc -L./ -llolo -o static_app test_lolo.o
undefined reference to `lolo_add2'
collect2: error: ld returned 1 exit status

This is soooo weird! Any comment?!

  • See also [Undefined reference to 'pthread_create' — linker command option order (libraries before/after object files?)](https://stackoverflow.com/q/9253200/15168) – Jonathan Leffler Jul 28 '21 at 23:14

0 Answers0