0

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.

machine yearning
  • 9,889
  • 5
  • 38
  • 51

1 Answers1

1

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)

Attila
  • 28,265
  • 3
  • 46
  • 55
  • 1
    It probably was compiled with a different configuration setting than the one installed on the system. Look up the parameters for the BOOST build process – Attila Apr 16 '12 at 01:49
  • Oh spoke too soon: now when I run the executable I get the error *error while loading shared libraries: libboost_thread.so.1.49.0: cannot open shared object file: No such file or directory*. – machine yearning Apr 16 '12 at 01:50
  • I'm not that familiar with the linux environment, but I think you will need to set one of the environmental variables so the executable can find the shared library (try PATH first: `export PATH=$PATH:./lib`) – Attila Apr 16 '12 at 01:52
  • 1
    Actually it seems like you need [`LD_LIBRARY_PATH`](http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html) – Attila Apr 16 '12 at 01:53