简体   繁体   中英

I installed libboost but can't link to it

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 ?

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 ...

在Ubuntu 16.04中,该软件包的名称为:libboost-all-dev(不是libboost-dev-all)

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM