我已经通过apt-get
安装了libboost-dev
,它放在/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
但是当我尝试编译使用 boost_thread
的源代码时,我仍然遇到错误。
$ 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
安装和链接到 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
我认为这是重点。这意味着我以错误的方式安装了 libboost
。其实我只安装了libboost-dev
:
sudo apt-get install libboost-dev
但是我应该做的是:
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
(或者,在我的特殊情况下,至少安装 libboost-system1.46-dev libboost-thread1.46-dev
)
一旦你正确安装它们,/usr/lib
中应该有 .a
和 .so
。
/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 ...
关于c++ - 我安装了 libboost 但无法链接到它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11137398/