Possible Duplicate:
Linker order - GCC
GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference to 'ClassName::ClassName()'
I am using GCC to build an application. The main program calls a function (say, myfunc()
)that resides in a static library (say, libmylib.a
). This function calls the cosf()
and sinf()
function from math library.
Now, in gcc command line, I give the -lmylib -lm
options, and the build goes fine. However, when the order of the libraries is changed, then the build fails with the error:
libmylib.a(mylib.o): In function `myfunc':
mylib.c:22: undefined reference to `cosf'
mylib.c:23: undefined reference to `sinf'
Why doesn't gcc complete the build with the libraries given in some order?