7
votes

I've got a project which links against various common libraries, as well as Boost. Testing this on computers other than my own has proven to be difficult since various flavors of Linux come with different versions of Boost. I would prefer to avoid having to download and compile the same version of Boost on every machine.

Is there a way to link my program statically only with the Boost libraries and have everything else linked normally? I've tried linking everything statically (-static), but that causes other problems (namely lGL is not found). Is there an other potential way I could package only the necessary dynamic libraries with my program (say in the same folder as the executable) and distribute it that way?

Link error when trying to link everything statically:

g++ -static -o"acmserver"  ./src/acmserver.o ./src/airplane.o ./src/bullet.o ./src/control.o ./src/detail.o ./src/game.o ./src/gamelog.o ./src/gamelogitem.o ./src/guns.o ./src/map.o ./src/missile.o ./src/missilepod.o ./src/object.o ./src/server.o   -lboost_system -lboost_filesystem -lboost_thread -lboost_serialization -lboost_date_time -lpthread -lGLU -lGL
/usr/bin/ld: cannot find -lGL
collect2: ld returned 1 exit status
make: *** [acmserver] Error 1

EDIT (SOLUTION):

count0 mentioned exactly what I was looking for. In Eclipse I removed all the Boost libraries (e.g., boost_system) form Project -> Properties -> C/C++ Build -> Settings -> GCC C++ Linker -> Libraries -> Libraries (-l). Then I added the Boost .a files (e.g., /usr/lib/libboost_system.a) under Project -> Properties -> C/C++ Build -> Settings -> GCC C++ Linker -> Miscellaneous -> Other Objects. I also removed the "-static" from the linker flags. This produced an executable with all of the boost libraries linked statically instead of dynamically.

2

2 Answers

8
votes

Use the boost archive files (.a files) instead of the shared lib files (.so aka. linking with -l). You are linking those boost libraries dynamically right now. Writing it out might help to ensure what is being linked statically and what dynamically.

This will look something like:

g++ -o"acmserver"  ./src/acmserver.o ... ./src/server.o \
  /usr/local/lib/libboost_system.a /usr/local/lib/boost_filesystem \
  ... -lGL ...

Depending on the gcc version or platform type you might also have to add the -static` flag.

0
votes

That error says your linker didn't found the GL library, which has nothing to do with boost.

Make sure you have libgl1-mesa-dev or an equivalent package installed on your system.