0

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?

Community
  • 1
  • 1
ysap
  • 7,723
  • 7
  • 59
  • 122
  • That is just the way it is. See for example http://stackoverflow.com/questions/3363398/g-linking-order-dependency-when-linking-c-code-to-c-code – Dirk Eddelbuettel Aug 28 '12 at 22:51
  • Strange that I did not see the linked questions - but given these, I agree that this question is a dup. – ysap Aug 28 '12 at 22:59

0 Answers0