如何在Linux中正确链接Boost库 [英] How to link boost libraries properly in Linux
问题描述
我一直在尝试Boost教程,但是我陷于链接文件系统库的问题.
I've been trying to go through Boost tutorials but I got stuck at linking the filesystem library.
我有Ubuntu 12.10.安装并不难
I have Ubuntu 12.10. Installation wasn't that hard
sudo apt-get install libboost-all-dev
这会将所有标头放在/usr/local/include中,并将已编译的源代码放在/usr/lib/中
[--headers]
[--binaries]
This put all headers in /usr/local/include and compiled sources in /usr/lib/
[--headers]
[--binaries]
我写了这个程序[--program].当我尝试编译它时
I wrote this program [--program]. When I tried to compiled it
g++ -g tut1.cpp -o tut1 -lboost_system -lboost_filesystem
忘记了以下错误:[--errors].
在 http://上稍作搜索后www.boost.org/doc/libs/1_53_0/more/getting_started/unix-variants.html
我试过了:
got this errors: [--errors].
After a little search on http://www.boost.org/doc/libs/1_53_0/more/getting_started/unix-variants.html
I tried this:
g++ -g -I /usr/local/include/boost/ tut1.cpp -o tut1 -L /usr/lib/libboost_filesystem.a -lboost_system -lboost_filesystem
但是没有运气.我有同样的错误.
but didn't have luck. I had the same errors.
由于我不能在帖子中放置超过2个链接,因此所有链接都
http://pastebin.com/DakVFn12
Since I cannot put more than 2 links in the post, here are all links
http://pastebin.com/DakVFn12
推荐答案
我在这里找到了答案:
http://www.richelbilderbeek.nl/CppLinkErrorUndefinedReferenceToBoostFilesystemDetailGet_current_path_api.htm
看起来二进制文件不在/usr/lib中,而在/usr/local/lib中.
因此,正确的编译命令将是:
I found the answer myself here:
http://www.richelbilderbeek.nl/CppLinkErrorUndefinedReferenceToBoostFilesystemDetailGet_current_path_api.htm
Looks like binaries weren't in /usr/lib but in /usr/local/lib.
So the correct command for compilation would be:
g++ -g tut1.cpp -o tut1 -L/usr/local/lib/ -lboost_filesystem
@Yuushi,那是1个问题.
@Yuus that was 1 problem.
这篇关于如何在Linux中正确链接Boost库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!