I installed libboost but can't link to it

13,665

Solution 1

One thing I notice is that you do have no libboost_thread.so. You have the versioned 1.46.1 file but usually libraries will create a symbolic link to the versioned copy with the undecorated name. That might not be it but it's one thing I noticed. (This is typically done by the installer.) – Omaha

I think this is the point. It imply that I installed libboost the wrong way. In fact, I only installed libboost-dev:

sudo apt-get install libboost-dev 

But what should I do is:

sudo apt-get install libboost-dev libboost1.46-doc libboost-date-time1.46-dev ibboost-filesystem1.46-dev libboost-graph1.46-dev libboost-iostreams1.46-dev libboost-math1.46-dev libboost-program-options1.46-dev libboost-python1.46-dev libboost-random1.46-dev libboost-regex1.46-dev libboost-serialization1.46-dev libboost-signals1.46-dev libboost-system1.46-dev libboost-test1.46-dev libboost-thread1.46-dev libboost-wave1.46-dev

(Or, in my particular case, install libboost-system1.46-dev libboost-thread1.46-dev at least)

And once you install them correctly, there should be .a and .so in /usr/lib.

/usr/lib$ ls | grep boost
libboost_date_time.a
libboost_date_time-mt.a
libboost_date_time-mt.so
libboost_date_time.so
libboost_date_time.so.1.46.1
libboost_filesystem.a
libboost_filesystem-mt.a
... and so on ...

Solution 2

In Ubuntu 16.04, the package is named: libboost-all-dev (not libboost-dev-all)

Solution 3

The comment box screwed up the quoting of this suggestion, so I'm posting it as an answer to get correct quoting.

It used to be, Ubuntu had the meta-package libboost-dev-all to install all of those. However, I can't seem to find it now. Here's a command line that might help:

sudo apt-get install `apt-cache search libboost | \
    grep -- -dev | \
    grep -v '[12]\.[0-9]' | \
    awk '{ print $1; }'`

(Taken from https://github.com/imvu-open/istatd/ file install-boost-dev.sh )

Share:
13,665
Lai Yu-Hsuan
Author by

Lai Yu-Hsuan

Updated on July 24, 2022

Comments

  • Lai Yu-Hsuan
    Lai Yu-Hsuan almost 2 years

    I have installed libboost-dev through apt-get, and it's placed in /usr/lib.

    /usr/lib$ ls | grep boost
    libboost_filesystem.so.1.46.1
    libboost_iostreams.so.1.46.1
    libboost_serialization.so.1.46.1
    libboost_system.so.1.46.1
    libboost_thread.so.1.46.1
    libboost_wserialization.so.1.46.1
    

    But when I tried to compile a source that uses boost_thread I still got a error.

    $ g++ tcp_echo.cpp -o tcp_echo -L/usr/lib -llibboost_thread
    /usr/bin/ld: cannot find -lboost_thread
    collect2: ld returned 1 exit status
    $ g++ tcp_echo.cpp -o tcp_echo -L/usr/lib -lboost_thread
    /usr/bin/ld: cannot find -lboost_thread
    collect2: ld returned 1 exit status
    

    What's the right way to install and link to libboost?

  • Jon Watte
    Jon Watte about 9 years
    It used to be, Ubuntu had the meta-package libboost-dev-all to install all of those. However, I can't seem to find it now. Here's a command line that might help: sudo apt-get install ``apt-cache search libboost | grep -- -dev | grep -v '[12]\.[0-9]' | awk '{ print $1; }'
  • Matt S.
    Matt S. almost 9 years
    for others -- I had exactly the problem the OP had, and this command indeed instantly solved it. ubuntu 15.10 . Incidentally, 'libboost-dev' seems to not imply the missing 'libboost-dev-all'