编译并使用Boost 1.57
来源:互联网 发布:mac 无线投影到显示器 编辑:程序博客网 时间:2024/05/08 19:34
windows下boost库编译
1.首先在http://www.boost.org/下载源代码。
2.解压源代码到磁盘(如D:\boost_1_57_0)。
3.生成bjam.exe可执行文件:
用VS2010的命令行来实现,后期也是使用VS2010的命令行来实现boost库的编译。步骤为:
点击开始—>所有程序--> Microsoft Visual Studio 2010-->VisualStudio tools--> Visual Studio 2010 command prompt。
打开VisualStudio 2010 command prompt后进入boost的解压目录:
(1)cd命令进入源代码解压的目录(D:\boost_1_57_0);(2)执行bootstrap.bat;此时会在该目录下生成b2.exe、bjam.exe、project-config.jam文件。
4.用bjam.exe编译
运行命令bjam stage --without-python --toolset=msvc-10.0 --build-type=complete --stagedir="D:\boost_1_57_0\bin\vc10" link=static runtime-link=shared threading=multi debug release (这里红色部分是编译后库文件所在位置,根据自己需要设置)。
stage表示只生成库(dll和lib),用install的话还会生成包含头文件的include目录。<pre name="code" class="cpp"> toolset指定编译器,VS2010用msvc-10.0。 without/with表示不编译/编译哪些库。 stagedir,当使用stage时用stagedir,使用install用prefix,表示编译生成文件的路径。路径的命名最好和编译器相关,编译管理。 link指定生成动态链接库或静态链接库。生成动态链接库需使用shared方式,生成静态链接库需使用static方式。 runtime-link,动态/静态链接C/C++运行时库。有shared和static两种方式,这样runtime-link和link一共可以产生4种组合方式。 threading,单/多线程编译。 debug/release,编译debug/release版本。一般都是程序的debug版本对应库的debug版本,所以两个都编译。
5.编译好后,在根目录会有个bin.v2文件夹,是编译过程中的临时文件夹,很大,可以手动删除
boost库使用
新建工程后需要把Boost库包含到工程中,右键选择属性,在VC++目录的“包含目录”中添加Boost的根目录,在“库目录”添加刚刚编译生成的位置再加上路径lib。
boost库使用测试
这里以boost库中的散列库unordered库使用为例。
#include <iostream>using namespace std;using namespace boost;#include "boost/unordered_map.hpp"int main() {unordered_map<string, int> m;m.insert(make_pair("Tom", 20));m.insert(make_pair("adission", 13));m.insert(make_pair("Window", 44));unordered_map<string, int>::iterator iter = m.begin();while (iter != m.end()) {cout << iter->first << " " << iter->second << endl;iter++;}cout << endl;}http://write.blog.csdn.net/postedit/42532527
linux下独立编译、使用boost.regex
本部分参看:Here
下载好了Boost库,下面开始编译, 下面是具体的步骤:(假设下载完后的,代码解压在了BOOST_DIR目录)
(1)进入到BOOST_DIR/libs/regex/build目录
(2)如果要使用静态库,请执行make -fgcc.mak
(3)如果要使用静态库,请执行make -fgcc-shared.mak
执行完上面三步后的,在BOOST_ROOT/libs/regex/build/下会生成一个gcc目录 ,进入该目录 ,可以看到生成了下面四个文件:
(1)libboost_regex-gcc-1_42.a , 这是release版的静态库
(2)libboost_regex-gcc-1_42.so, 这是release版的动态库(共享库)
(3)libboost_regex-gcc-d-1_42.a, 这是debug版的静态库
(4)libboost_regex-gcc-d-1_42.so, 这里debug版的动态库(共享库)
注意:
在下面的例子中,使用./boost_regex之前,需要在shell中运行:export LD_LIBRARY_PATH=path, path为你的libboost_regex-gcc-d-1_53.so所在的目录,然后再运行你的程序。我的是:export LD_LIBRARY_PATH=/home/yang/boost_1_59_0/libs/regex/build/gcc。否则会出现如下的问题,找不到动态库:
---------补充-------后来在其他程序中同样遇到了.so无法找到的问题,但是用上述方法却没办法解决,只能将找不到的.so文件拷贝到系统/lib目录下来解决。所以,使用LD_LIBRARY_PATH临时解决的方法,我不知道问题出现在哪里。
对boost.regex的使用
//编译: g++ -L /home/yang/boost_1_59_0/libs/regex/build/gcc -lboost_regex-gcc-d-1_53 -I /home/yang/boost_1_59_0/ -o boost_regex boost_regex.cpp#include <string> #include <iostream> #include "boost/regex.hpp" using namespace std;int main(int argc, char ** argv) { const char* mail = "1234@test.com"; boost::cmatch res; //建立3个子表达式 boost::regex reg("(\\w+)@(\\w+).(\\w+)"); if (boost::regex_match(mail,res, reg)) { //既可以通过迭代器获取数据, 也可以通过数组方式获取数据 for (boost::cmatch::iterator pos = res.begin(); pos != res.end(); ++pos){ std::cout << *pos << " "; }cout << endl; //res[0]存放匹配到的完整字符串 std::cout << "name:" << res[1] << " " << res[2]<< " " << res[3] <<std::endl; }}
g++ -I选项指定boost.regex头文件所在的目录
g++ -L指定boost.regex库所在的位置
- 编译并使用Boost 1.57
- 在Android编译并使用boost
- Mac上编译并使用 boost
- window vs编译并使用Boost库
- window vs编译并使用Boost库
- windows-qt 使用mingw编译c++boost并使用
- 编译并使用boost库(win7+boost1.53+vs2012)
- boost 1.56.0 编译及使用,并记要点
- 编译并使用Boost库(Win7+Boost1.53+VS2012)
- 编译并使用Boost库(Win7+Boost1.53+VS2012)
- 编译并使用boost库(win7+boost1.60+vs2013)
- boost 1.56.0 编译及使用,并记要点
- 编译并使用boost库(win7+boost1.60+vs2013)
- Ubuntu编译安装boost并在eclipse C/C++中使用/Boost安装和卸载
- Linux系统下编译Boost库,并在Qt Creator中使用Boost库
- Linux系统下编译Boost库,并在Qt Creator中使用Boost库 .
- 使用MinGW编译boost
- 使用bjam编译boost
- 从英国幼儿园“成绩单”说开去
- WPF Incanvas中墨迹的移动缩放 与复位
- bzoj1061: [Noi2008]志愿者招募 费用流
- 白盒加密技术
- 关于 Unity 的一麻袋小玩意(原文转载)
- 编译并使用Boost 1.57
- 数字图像处理与识别技术概况
- 编程的艺术
- ubuntu 下 codeblocks 的使用 各种技巧转自
- sencha touch -- store.load传参数
- 【哈希表】实现结构RandomPool,用O(1)时间完成插入、删除和随机返回的功能
- unity--怪物打主角
- hdu 1713 相遇周期 (GCD & LCM)
- 黑马程序员_流程控制语句