EPD中已自带Mingw,如何安装c++ boost库?
来源:互联网 发布:云南边境贩毒知乎 编辑:程序博客网 时间:2024/06/05 17:20
由于已安装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窗口下运行如下命令
- REM 生成b2.exe和bjam文件::
- bootstrap.bat gcc
REM 生成b2.exe和bjam文件::bootstrap.bat gcc
3.将boost安装到指定目录
- REM 安装到一个指定的目录,比如 C:\boost :
- bjam install --toolset=gcc --prefix=C:\boost
REM 安装到一个指定的目录,比如 C:\boost :bjam install --toolset=gcc --prefix=C:\boost
如果要安装到默认目录(c:\boost)只需运行如下命令即可
- b2 install --toolset=gcc
b2 install --toolset=gcc
然后是漫长的等待...大概8分钟左右
4.注意include和Lib分别为,include可加入系统的Path变量中,Lib在gcc和g++中需要使用-Llib指定
- C:\boost\include\boost-1_49
- C:\boost\lib
C:\boost\include\boost-1_49C:\boost\lib
随便找个例子就可以测试了boost了.
例如编译regex库的例子:
- #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";elsestd::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
可以如下编译:
- 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.aREM #也可以这样编译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变量中.
那么以下就可以了:
- 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的效果一样,很方便:
- 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_49set BoostLIB=C:\boost\libg++ -o test test.cpp -I$(BoostInclude) -L$(BoostLIB) -lboost_regex-mgw45-mt-1_49
双击一下testbuild.bat就行了.
- EPD中已自带Mingw,如何安装c++ boost库?
- EPD中已自带Mingw,如何安装c++ boost库?
- mingw中安装boost库
- Mingw下安装BOOST
- MinGW下安装boost
- Canopy(EPD)的安装
- MinGW的安装以及如何配置C
- Mingw编译Boost库
- Mingw编译Boost库
- 如何安装boost库
- MinGW 环境Boost库的编译及安装
- CodeBlocks 使用自带的MinGW调试
- 如何安装MinGW
- C#MVC中自带验证
- (CodeBlocks+MingW)安装和使用Boost
- (CodeBlocks+MingW)安装和使用Boost(转载)
- (CodeBlocks+MingW)安装和使用Boost
- 以minGW编译boost库,并在Code::Blocks中设置boost空应用程
- Andriod中绘(画)图----Canvas的使用详解 .
- 在 ubuntu 平台上 编译 gstreamer 0.10
- Android中SQLiteDatabase操作【附源码】
- Java 解惑(Java Puzzler)
- Core Animation教学:如何使用CALayer的遮罩(mask)
- EPD中已自带Mingw,如何安装c++ boost库?
- linux内存映像
- linux 设备模型
- jQuery 1.7以后版本使用on代替live
- 对 u-boou1.1.6的do_go修改(最好不动)
- android与HTML5相结合实现的省市县三级联动
- MyEclipse8.6插件安装方法
- Ocp 正则表达式 详解
- DLL和exe里的malloc和free不能混用