Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I installed libboost but can't link to it

Tags:

c++

linker

boost

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?

like image 974
Lai Yu-Hsuan Avatar asked Jun 21 '12 11:06

Lai Yu-Hsuan


1 Answers

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 ...
like image 53
Lai Yu-Hsuan Avatar answered Sep 23 '22 20:09

Lai Yu-Hsuan