This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
problem with order of -lmylibrary flags.
- From: Brendan Miller <catphive at catphive dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 20 May 2012 16:16:03 -0700
- Subject: problem with order of -lmylibrary flags.
I've found kind of a weird issue where if I indicate I want to link a
library with the -l flag too early on the command line, I get linker
errors.
Here's an example:
g++ -lml -lcvaux -lhighgui -lcv -lcxcore -std=c++0x -Werror -Wall -g
-MMD -MP -Iinclude -o objrec main.cpp
Here I'm linking a bunch of libraries, into a binary called objerec.
The source file is at the end. This command line produces linker
errors as if the libraries had not been linked properly.
However in this example everything is fine:
g++ -std=c++0x -Werror -Wall -g -MMD -MP -Iinclude -o objrec
main.cpp -lml -lcvaux -lhighgui -lcv -lcxcore
The only difference is that I place the -l flags after the source file
(main.cpp) that I'm building.
Why does the second example compile while the first gets linker errors?
A more general question: in a make file is it better to list libraries
you want to link in the LDFLAGS variable, or in the LDLIBS variable?
Thanks,
Brendan Miller