我试图在Linux机器上安装Boost(CentOs,Linux版本2.6.9-67.ELsmp).我按照Boost 入门网页上的说明进行操作.下载并解压缩文件,然后我添加前缀,因为我不是root用户.
./bootstrap.sh --prefix=/my_path/boost-1.49.0
./b2 install
Run Code Online (Sandbox Code Playgroud)
我转到/my_path/boost-1.49.0并检查那里有/ include/boost /和/ lib /包含文件.
我也将LD_LIBRARY_PATH设置为/my_path/boost-1.49.0/lib/.
要测试我是否成功安装,我编译以下代码:
main.cpp中
#include <boost/regex.hpp>
#include <iostream>
#include <string>
using namespace boost;
using namespace std;
int main(int argc, char *argv[])
{
string line = "12345";
regex pattern("^123");
if (regex_match(line, pattern)) cout << "match." << endl;
else cout << "not match." << endl;
return 1;
}
Run Code Online (Sandbox Code Playgroud)
并按命令编译:
g++ -v -I /my_path/boost-1.49.0/include/boost -L /my_path/boost-1.49.0/lib main.cpp -lboost_regex -o example
Run Code Online (Sandbox Code Playgroud)
并生成以下错误:
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared …Run Code Online (Sandbox Code Playgroud)