I have quite a complex build which involves many static and shared libraries being linked into an executable on Ubuntu 14.04 using G++ 4.8. The example is too complex to reproduce here, but it amounts to this:
I use functions from the boost filesystem library in my code, then archive that into a static library, call it my_lib.a
.
I then link like this:
g++ -g -o Build/main -L Build/libs -Wl,--start-group ...lots of libraries here... \
Build/libs/my_lib.a -lboost_filesystem -Wl,--end-group
When I run this, I get:
/usr/bin/ld: Build/my_lib.a(my_code.o): undefined reference to symbol '_ZN5boost10filesystem4pathdVERKS1_'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_filesystem.so: error adding symbols: DSO missing from command line
From what I can tell from Google, this means that I should add -lboost_filesystem
to my link command-line - but it is already there! I understand that the order of libraries is usually also important, but I thought that surrounding the objects and libraries with -Wl,--start-group
and -Wl,--end-group
should make that irrelevant - and in any case, I think I've got the order right. So what's going on?