Eclipse & MinGW & Boost 配置


版权所有, 禁止转载, 如有需要, 请站内联系

本文地址: http://blog.csdn.net/caroline_wendy/article/details/17282187


Boost作为C++的一个最关键的库, 是每一个C++编程人员需要使用的, 本文讲解如何在Eclipse+MinGW下配置boost库;


1. Eclipse安装CDT插件和MinGW

可以按照如下链接完美配置; 地址: http://blog.csdn.net/caroline_wendy/article/details/17039847;


2. 下载boost

下载boost最新版本MinGW的文件下, 并解压, 最新版本: http://www.boost.org/users/history/version_1_55_0.html

windows环境比linux难配置, 所以选择讲解windows版本;



3. 编译boost

由于boost有些库, 如regex(正则), 需要手动编译, 不能直接使用;

点击, 根目录下的"bootstrap.bat"文件, 会生成"bjam.exe", 文件, 最终编译出的库会生成在stage文件夹中;


如果直接双击bjam是生成的VS版本的库文件;

如果生成MinGW的GCC版本的库文件, 需要输入命令"bjam.exe  --build-type=complete toolset=gcc stage"

如图, 已经编译结束:



4. 项目配置boost库

添加系统环境变量Path, 使系统可以找到dll, "XXX\boost\stage\lib", XXX为具体路径; 注销或重启电脑;

主要包含两个位置, 一个是include目录, 一个lib目录, 具体位置, 如添加regex库, 如图:




5.测试代码:

#include <boost/regex.hpp> #include <iostream> #include <iterator> #include <algorithm>  using namespace std; using namespace boost;  int main() { 	string pattern("[^c]ei"); 	pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*"; 	regex r(pattern); 	smatch results; 	string test_str = "receipt freind theif receive"; 	if(regex_search(test_str, results, r)) 		cout << results.str() << std::endl; }