EPD中已自带Mingw,如何安装c++ boost库?
2012-09-06 17:14
316 查看
由于已安装Python的科学计算套件epd-7.2-2-win-x86.msi,里面已自带了GNU(MinGW)的gcc,g++和gfortran等编译器,还想测试一下如何安装c++ boost库?
基本过程是这样的:
1.下载boost_1_49_0
2.解压缩后进入目录boost_1_49_0,在DOS窗口下运行如下命令
[plain]
view plaincopyprint?
REM 生成b2.exe和bjam文件:: bootstrap.bat gcc
3.将boost安装到指定目录
[plain]
view plaincopyprint?
REM 安装到一个指定的目录,比如 C:\boost : bjam install --toolset=gcc --prefix=C:\boost
如果要安装到默认目录(c:\boost)只需运行如下命令即可
[plain]
view plaincopyprint?
b2 install --toolset=gcc
然后是漫长的等待...大概8分钟左右
4.注意include和Lib分别为,include可加入系统的Path变量中,Lib在gcc和g++中需要使用-Llib指定
[sql]
view plaincopyprint?
C:\boost\include\boost-1_49 C:\boost\lib
随便找个例子就可以测试了boost了.
例如编译regex库的例子:
[cpp]
view plaincopyprint?
#include <boost/regex.hpp>
#include <string>
#include <iostream>
int main() {
std::cout << "Enter a regular expression:\n";
std::string s;
std::getline(std::cin, s);
try {
boost::regex reg(s);
std::cout << "Enter a string to be matched:\n";
std::getline(std::cin, s);
if (boost::regex_match(s, reg))
std::cout << "That's right!\n";
else
std::cout << "No, sorry, that doesn't match.\n";
}
catch(const boost::bad_expression & e) {
std::cout << "Invalid Regular Expression!" << std::endl;
std::cout << "Error::" << e.what() << std::endl;
}
return 0;
}
regex库在boost安装的时候已经生成了两个链接库文件:
libboost_regex-mgw45-mt-1_49.a
libboost_regex-mgw45-mt-d-1_49.a
可以如下编译:
[plain]
view plaincopyprint?
REM #可以这样编译
g++ -o test test.cpp -IC:\boost\include\boost-1_49 C:\boost\lib\libboost_regex-mgw45-mt-1_49.a
REM #也可以这样编译
g++ test.cpp -IC:\boost\include\boost-1_49 -LC:\boost\lib\ -lboost_regex-mgw45-mt-1_49
使用g++编译时随便选一个都行,如果不想每次都写-IC:\boost\include\boost-1_49,可以将其加入系统路径,即path变量中.
那么以下就可以了:
[cpp]
view plaincopyprint?
g++ test.cpp -LC:\boost\lib\ -lboost_regex-mgw45-mt-1_49
记住,采用第二种方法编译时,链接库的文件名前缀(lib)和后缀(.a)是不需要写上的.
将以下文件保存为testbuild.bat文件,用起来和makefile的效果一样,很方便:
[plain]
view plaincopyprint?
set BoostInclude=C:\boost\include\boost-1_49
set BoostLIB=C:\boost\lib
g++ -o test test.cpp -I$(BoostInclude) -L$(BoostLIB) -lboost_regex-mgw45-mt-1_49
双击一下testbuild.bat就行了.
基本过程是这样的:
1.下载boost_1_49_0
2.解压缩后进入目录boost_1_49_0,在DOS窗口下运行如下命令
[plain]
view plaincopyprint?
REM 生成b2.exe和bjam文件:: bootstrap.bat gcc
REM 生成b2.exe和bjam文件:: bootstrap.bat gcc
3.将boost安装到指定目录
[plain]
view plaincopyprint?
REM 安装到一个指定的目录,比如 C:\boost : bjam install --toolset=gcc --prefix=C:\boost
REM 安装到一个指定的目录,比如 C:\boost : bjam install --toolset=gcc --prefix=C:\boost
如果要安装到默认目录(c:\boost)只需运行如下命令即可
[plain]
view plaincopyprint?
b2 install --toolset=gcc
b2 install --toolset=gcc
然后是漫长的等待...大概8分钟左右
4.注意include和Lib分别为,include可加入系统的Path变量中,Lib在gcc和g++中需要使用-Llib指定
[sql]
view plaincopyprint?
C:\boost\include\boost-1_49 C:\boost\lib
C:\boost\include\boost-1_49 C:\boost\lib
随便找个例子就可以测试了boost了.
例如编译regex库的例子:
[cpp]
view plaincopyprint?
#include <boost/regex.hpp>
#include <string>
#include <iostream>
int main() {
std::cout << "Enter a regular expression:\n";
std::string s;
std::getline(std::cin, s);
try {
boost::regex reg(s);
std::cout << "Enter a string to be matched:\n";
std::getline(std::cin, s);
if (boost::regex_match(s, reg))
std::cout << "That's right!\n";
else
std::cout << "No, sorry, that doesn't match.\n";
}
catch(const boost::bad_expression & e) {
std::cout << "Invalid Regular Expression!" << std::endl;
std::cout << "Error::" << e.what() << std::endl;
}
return 0;
}
#include <boost/regex.hpp> #include <string> #include <iostream> int main() { std::cout << "Enter a regular expression:\n"; std::string s; std::getline(std::cin, s); try { boost::regex reg(s); std::cout << "Enter a string to be matched:\n"; std::getline(std::cin, s); if (boost::regex_match(s, reg)) std::cout << "That's right!\n"; else std::cout << "No, sorry, that doesn't match.\n"; } catch(const boost::bad_expression & e) { std::cout << "Invalid Regular Expression!" << std::endl; std::cout << "Error::" << e.what() << std::endl; } return 0; }
regex库在boost安装的时候已经生成了两个链接库文件:
libboost_regex-mgw45-mt-1_49.a
libboost_regex-mgw45-mt-d-1_49.a
可以如下编译:
[plain]
view plaincopyprint?
REM #可以这样编译
g++ -o test test.cpp -IC:\boost\include\boost-1_49 C:\boost\lib\libboost_regex-mgw45-mt-1_49.a
REM #也可以这样编译
g++ test.cpp -IC:\boost\include\boost-1_49 -LC:\boost\lib\ -lboost_regex-mgw45-mt-1_49
REM #可以这样编译 g++ -o test test.cpp -IC:\boost\include\boost-1_49 C:\boost\lib\libboost_regex-mgw45-mt-1_49.a REM #也可以这样编译 g++ test.cpp -IC:\boost\include\boost-1_49 -LC:\boost\lib\ -lboost_regex-mgw45-mt-1_49
使用g++编译时随便选一个都行,如果不想每次都写-IC:\boost\include\boost-1_49,可以将其加入系统路径,即path变量中.
那么以下就可以了:
[cpp]
view plaincopyprint?
g++ test.cpp -LC:\boost\lib\ -lboost_regex-mgw45-mt-1_49
g++ test.cpp -LC:\boost\lib\ -lboost_regex-mgw45-mt-1_49
记住,采用第二种方法编译时,链接库的文件名前缀(lib)和后缀(.a)是不需要写上的.
将以下文件保存为testbuild.bat文件,用起来和makefile的效果一样,很方便:
[plain]
view plaincopyprint?
set BoostInclude=C:\boost\include\boost-1_49
set BoostLIB=C:\boost\lib
g++ -o test test.cpp -I$(BoostInclude) -L$(BoostLIB) -lboost_regex-mgw45-mt-1_49
set BoostInclude=C:\boost\include\boost-1_49 set BoostLIB=C:\boost\lib g++ -o test test.cpp -I$(BoostInclude) -L$(BoostLIB) -lboost_regex-mgw45-mt-1_49
双击一下testbuild.bat就行了.
相关文章推荐
- EPD中已自带Mingw,如何安装c++ boost库?
- 如何在Windows7操作系统下安装用于C++开发的Eclipse
- ubuntu系统自带的火狐(firefox)如何安装Adobe Flash
- Eclipse C C++ 中文语言包获取及安装MinGW
- 如何用MinGW 命令行编译链接c/c++
- PHP5不重新编译,如何安装自带的未安装过的扩展,如soap扩展?
- Eclipse 如何安装并配置C++开发环境(Linux下)
- Boost库在XP+Visual C++.net中的安装
- 如何用新安装的JDK替换掉Linux系统自带的gij编译工具
- 安装Qt+MinGW+Eclipse for c_c++开发环境配置总结
- 使用mingw-get.exe命令行工具在Windows平台上安装C++等语言的编译工具
- windows下Eclipse+MinGW+Qt+c++配置安装解决方法
- lenovo-G50自带win8如何改成安装win7
- 如何在自己的App中调用Android系统自带的安装/卸载程序
- Microsoft Dynamics CRM 2015 数据管理 之 如何批量导入数据到 正式区(二)系统自带示例数据 安装及教学
- 如何安装mingw(提供网盘下载!)
- centOS下自带安装了apache和php,如何配置呢 ?
- 如何安装VS.NET2003中文版自带的QuickStart
- Windows下如何更新 CodeBlocks 中的 MinGW 使其支持新版本 C++
- 安装MinGW,搭配Notepad++编译C++