在Linux中安装和构建Boost库

我正在关注 Boost Getting Started的文章.
我已经用Bjam安装了它,我可以看到包含文件和库文件(.a,.so).
#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
}

如果我使用此命令构建上面的代码

g++ -I./boost/include -L./boost/lib -lboost_regex-gcc43-mt -static -o test_boost2 test_boost2.cc

我收到此错误:

/tmp/ccJFVVid.o: In function `boost::basic_regex<char,boost::regex_traits<char,boost::cpp_regex_traits<char> > >::assign(char const*,char const*,unsigned int)':
    test_boost2.cc:(.text._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[boost::basic_regex<char,unsigned int)]+0x22): undefined reference to `boost::basic_regex<char,boost::cpp_regex_traits<char> > >::do_assign(char const*,unsigned int)'
    collect2: ld returned 1 exit status

它在我的Windows机器下工作正常.

怎么了?

gcc版本4.3.2(Debian 4.3.2-1.1)

Linux xxxxxxxx 2.6.26-1-686#1 SMP Fri Mar 13 18:08:45 UTC 2009 i686 GNU / Linux

解决方法

sudo apt-get install libboost-regex-dev

不要在更智能的系统可以做得更好的源头安装.

要编译,只需使用

g++ -lboost_regex boost.cpp -o boost

获取可用软件包名称列表(更多部分的boost):

apt-cache search libboost | grep -- -dev

免责声明:我假设您使用Debian,因为这是您的GCC版本报告的内容.

相关文章

linux常用进程通信方式包括管道(pipe)、有名管道(FIFO)、...
Linux性能观测工具按类别可分为系统级别和进程级别,系统级别...
本文详细介绍了curl命令基础和高级用法,包括跳过https的证书...
本文包含作者工作中常用到的一些命令,用于诊断网络、磁盘占满...
linux的平均负载表示运行态和就绪态及不可中断状态(正在io)的...
CPU上下文频繁切换会导致系统性能下降,切换分为进程切换、线...