+1  A: 
  • One possibility is to check the file list of the rpm/deb package. On a Ubuntu system this could be done by issuing the following command:

dpkg -L libboost-filesystem-dev

  • Another possibility is to use pkg-config. It is a program that helps determine the compile flags for certain libraries (eventhough it does not support boost on Ubuntu)

  • You could use Autoconf - a macro that checks for boost can be found here. Using Autoconf helps keeping your sources platform/distribution independent.

David Feurle
Thanks. I'll investigate all these possibilities.
augustin
+1  A: 

There is a brute-force method I sometimes use, but you do have to know what directories to look in for the library you need (/lib, /usr/lib and /usr/local/lib are the usual suspects). I've created a shell script I call "gnm," (short for "grep nm," the two utilities it uses) with the below contents. If you create such a text file, remember to make it executable (chmod +x gnm).

#!/bin/sh
if [ $# -lt 2 ] ; then
  echo Usage: $0 pattern file[s]
  exit
fi
pattern=$1
shift
while [ $# -gt 0 ] ; do
  nm $1 | grep $pattern > /dev/null
  if [ $? -eq 0 ] ; then
    echo $1
  fi
  shift
done

When I'm searching for a library that defines a particular symbol, I issue a command something like:

gnm symbol /usr/lib/*.a 

For example, the source you mentioned gives me the following link errors:

boost_example.cpp:(.text+0x38): undefined reference to `boost::system::get_system_category()'
boost_example.cpp:(.text+0x44): undefined reference to `boost::system::get_generic_category()'
boost_example.cpp:(.text+0x50): undefined reference to `boost::system::get_generic_category()'
boost_example.cpp:(.text+0x5c): undefined reference to `boost::system::get_generic_category()'
boost_example.cpp:(.text+0x68): undefined reference to `boost::system::get_system_category()'

so I use the command:

gnm get_system_category /usr/lib/*.a

which reports:

/usr/lib/libboost_filesystem.a
/usr/lib/libboost_system.a

Trying the first of these results in the same errors, but the second one works:

g++ boost_example.cpp -lboost_system -o run

I don't know why I needed the system library where you needed filesystem; maybe different versions of Boost.

Dave Taflin
Nifty! Thanks. I'll try that next time.
augustin
A: 

I just found the most intelligent and most official way (on my system) to figure out the link flag. What follows is only valid for boost on a Debian or Debian derivative distribution (like Kubuntu in my case). The other replies might be more generic for any library on any system.

Depending on the boost version installed, you may have the following file on your Debian-like distribution:
/usr/share/doc/libboost1.38-doc/README.Debian
part of which reads:

--------

The following table shows which components use a library (shared or
static) and the corresponding "-l" flag.  Note that only the
multithreaded version of the libraries is shipped.

  Component              Link Flag                    Library Type
  ---------              ---------                    ------------
  Boost.Date_Time        -lboost_date_time-mt           static  shared
  Boost.Filesystem       -lboost_filesystem-mt          static  shared
  Boost.Graph            -lboost_graph-mt               static  shared
  Boost.IOStreams        -lboost_iostreams-mt           static  shared
  Boost.Math             -lboost_math_c99-mt            static  shared
                         -lboost_math_c99f-mt           static  shared
                         -lboost_math_c99l-mt           static  shared
  Boost.MPI              -lboost_mpi-mt                 static  shared
  Boost.Program_options  -lboost_program_options-mt     static  shared
  Boost.Python           -lboost_python-mt-py24         static  shared
                         -lboost_python-mt-py25         static  shared
  Boost.Regex            -lboost_regex-mt               static  shared
  Boost.Serialization    -lboost_serialization-mt       static  shared
                         -lboost_wserialization-mt      static  shared
  Boost.Signals          -lboost_signals-mt             static  shared
  Boost.System           -lboost_system-mt              static  shared
  Boost.Test             -lboost_prg_exec_monitor-mt    static  shared
                         -lboost_unit_test_framework-mt static  shared
  Boost.Thread           -lboost_thread-mt              static  shared
  Boost.Wave             -lboost_wave-mt                static  shared


One only had to find the proper place for the documentation!

augustin