Search code examples
c++boostlinkerboost-thread

Ignore a previous version of boost C++


I have to give a demo on a machine which contains an old version of the C++ boost library. Specifically I need boost::thread, in which I am using the lock member function of the mutex class. Unfortunately the old version (1.33.1) does not contain this method.

I don't have root access on the target machine, and I can't uninstall the previous version of boost. My solution was to pre-compile the updated library on the target machine and just link to the newer version of the library.

The library-compiling part went great, everything went off without a hitch, but when I tried to compile it still indicated that it was using the old version of boost. I did a bit of looking around (g++ noob here) and found out that you can manually specify a location to look for headers and libraries first using the -L and -I flags. I tried to use these with relative paths (since I don't know the directory from which the demo will be executed but I do know the relative path to my new boost libraries) and I came up with this:

-bash-3.2$ g++ -I./include -L./lib main.cpp -lthread
/usr/bin/ld: cannot find -lthread
collect2: ld returned 1 exit status

I've been trying all kinds of stuff, such as specifying a path deeper into the include/library directories, but with no luck, and I feel like I'm at a dead end. Any ideas? FYI, I'm looking to use boost 1.49.0.


Solution

  • Try:

    g++ -I./include -L./lib main.cpp -lboost_thread
    

    The name of the library you need to specify for -l is derived from the .so file: leave off the beginning lib and the .so (e.g. libboost_thread.so -> -lboost_thread)