vs2012编译boost
㈠ 如何编译libboost
您好,这样的:
1、当前boost最新版本为1.55,下载地址http://sourceforge.net/projects/boost/files/boost/1.55.0/
或者从官网(www.boost.org)下载最新版的BOOST源码,经过测试,2012和2013步骤相同,这里以2012为例。
2、打开VS2012 Native Tools Command,可以从开始--Microsoft Visual Studio 2012找到:将下载的 boost_1_55_0.zip 解压在F盘,例如 F:\boost_1_53_0,执行bootstrap.bat。
3、编译,可以简单的使用b2 install,也可以指定存放目录,或者寻找网上其它帮助文章。
查看帮助可以输入:.\b2 --help
比如要开启多线程编译:b2 install threading=multi
设置生成的是debug或者release
备注:如果是使用VS2013,请指定输出库类型,否则会缺一个lib文件:
"无法打开文件 libboost_thread_vc120_mt_sgd-1_55.lib"。
在2013时,我是使用下面的语句进行编译:
// 如果要获取动态库:
bjam install stage --toolset=msvc-12.0 --stagedir="C:\Boost\boost_vc_120" link=shared runtime-link=shared threading=multi debug release
// 如果是要获取静态库:
bjam install stage --toolset=msvc-12.0 --stagedir="C:\Boost\boost_vc_120" link=static runtime-link=static threading=multi debug release
其中,注意修改--toolset=msvc-12.0,将12.0修改成对应的vs版本号,12.0是VS2013的版本号。
目标地址也要修改成你所需的。
注意,不要漏了install,它会帮你把头文件集合到一个文件夹中。
编译过程有一个复制过程,编译需要的时间比较长,本次编译过程中,会在C盘根目录下生成一个boost文件夹,然后包含include和lib文件夹,这就是我们将要使用的头文件和库文件。
4、编译完了我们就使用编译在C盘中的文件。我将它们拷贝到了F盘,
需要简单的配置两个地方:这里使用绝对路径,也可以配置环境来使用。
5、然后建立了一个工程测试。 在BoostTest中新建一个控制台应用程序,下图三个文件分别是:
1) 将要使用的boost头文件和库文件。 2) 解压出的boost文件夹,就是使用这个文件夹来进行 1 -- 3步骤的。 3)BoostTest 测试工程。
#include <iostream>
#include <boost/thread/thread.hpp>
void hello()
{
std::cout << "Hello world, I'm a thread!" << std::endl;
}
int main()
{
boost::thread thrd(&hello);
thrd.join();
}
编译测试工程, 并运行,开始boost之旅吧。
㈡ 安装了多个版本vs怎么编译boost
boost有些库是不用安装的,仅需包含头文件库就行了。
但是有些很爽的库(thread,regex)需要根据不同的系统做不同的调整,所以必须编译。
编译的流程很简单,如果是windows操作系统,首先找到那个booststrap.bat的东西,然后在控制台下运行它,它会生成bjam.exe,然后就可以通过bjam来编译boost库了,在命令行下输入bjam --help看选项。
如果嫌麻烦,可以一次将boost库需要编译的全部编译了,bjam --build-type=complete,生成库全在stage目录下。
㈢ vs2012用boost 解析 xml
boost没有对xml专门支持,只是作为一种配置保存的方式
如果要使用property tree库可以办到
http://www.boost.org/doc/libs/1_55_0/doc/html/property_tree.html
如果要操作xml建议使用TinyXml等专门的库
㈣ 如何用Visual Studio 2010编译boost1.42库
64位windows平台,编译环境是VS2005,进入Visual Studio 2005 x64 Win64 Command Prompt(单纯的cmd也不一定不行,我没试)。把bjam.exe放在boost根目录下,进入根目录,执行:
bjam --toolset=msvc address-model=64 --with-thread stage
bjam --toolset=msvc address-model=64 --with-date_time stage
关键选项:“address-model=64 ”
64位linux平台,使用gcc编译。进入boost根目录,执行:
./bjam --toolset=gcc --with-thread stage
./bjam --toolset=gcc --with-date_time stage
linux平台下倒是简单,不过网上有篇文章介绍用如下命令编译,不知道是多此一举,还是适用于某些情况(非64位linux主机?)。
./bjam --toolset=gcc "-sBUILD=release <cxxflags>-m64" --with-thread stage
./bjam --toolset=gcc "-sBUILD=release <cxxflags>-m64" --with-date_time stage
唉。命令都很简单,可浪费了我不少时间。usage根本没写,去看boost build的嘛,页数n多不说,看完之后能否找到答案还是未知数。网上相关资料很少而且大多南辕北辙,只好一直搜索+尝试。其实我只是想要个64位版本的库而已,这应该不是啥稀罕的需求吧?
在windows平台下,编译出来的是否是64位类库,只有link 64位程序的时候才能发现。如果不是,link程序无法找到类库中定义的函数或者类。linux不知道,因为我整出来直接就是64位了,我也懒得再找一台32位linux主机折腾了。
在1.37之后的boost,如果想要使用boost::thread库,必须有boost::date_time库。当然这件事情又一如既往很酷地没有出现在容易看到的地方。而是让你链接错误后再去玩抓虫游戏。
㈤ 怎样在VS2013中安装配置boost
下载Boost库,这里我选择下载boost_1_55_0.zip
解压boost文件到本地目录(如G:\boost_1_55_0),可以发现解压后的文件中有一个bootstrap.bat文件。
然后以管理员身份打开cmd窗口,
上述命令执行完毕后可以发现G:\boost_1_55_0下新生成了一个bjam.exe文件
在命令窗口中输入语句:bjam.exe
此过程将默认根据系统已经安装好的编译工具(VS2008,2010,2012,2013)等编译相应的Lib文件、头文件等。(此步骤大概需要10分钟)
可以看到msvc 12.0,这是因为我系统中已经安装过了VS2013
msvc : 8.0是VS2005
msvc : 10.0是VS2010
msvc : 12.0是VS2012、VS2013
第5步执行成功后会有如下信息提示
至此我们已经完成了boost库的安装,下面需要配置一下VS2013了。新建一个VS2013控制台应用程序(工程名为boostest),添加如下代码
#include "stdafx.h"
#include <boost/lexical_cast.hpp>
#include <iostream>
using namespace std;
int main()
{
using boost::lexical_cast;
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("123.0123456789");
string s0 = lexical_cast<string>(a);
string s1 = lexical_cast<string>(b);
cout << "number: " << a << " " << b << endl;
cout << "string: " << s0 << " " << s1 << endl;
int c = 0;
try{
c = lexical_cast<int>("abcd");
}
catch (boost::bad_lexical_cast& e){
cout << e.what() << endl;
}
return 0;
}
添加boostest工程的包含目录和库目录
包含目录添加 G:\boost_1_55_0
库目录添加 G:\boost_1_55_0\stage\lib
进入代码窗口编译并成功运行说明BOOST库确实已经配置成功,可以放心使用。
㈥ 如何编译&使用boost库
1. 编译
1.2. VS2005编译boost_1_55_0
1.2.1. 使用vs2005的命令行执行:...\boost_1_55_0\bootstrap.bat
1.2.2. 编译动态库
bjam install stage --toolset=msvc-8.0 --stagedir="C:\Boost\boost_vc_80" link=shared runtime-link=shared threading=multi debug release
1.2.3. 编译静态库
bjam install stage --toolset=msvc-8.0 --stagedir="D:\Boost\boost_vc_80" link=static runtime-link=static threading=multi debug release
各种参数详解:
stage:表示只生成库(dll和lib)
install:还会生出包含的头文件
--toolset=msvc-8.0:指定编译器版本,8.0为vs2005,其他VS类推。
--stagedir:指定编译后存放的目录
link:生成动态库/静态库。动态库(shared),静态库(static)
runtime-link:动态/静态C/C++运行时库,同样有shared和static两种组合方式。这样共有4种组合方式,个人根据自己需要选择。
threading:单/多线程,一般都是多线程程序,当然multi了。
debug/release:编译版本,一般2个都需要。
2. 使用
使用静态库:
[cpp] view plain print?
//#define BOOST_ALL_DYN_LINK
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
使用静态库连接时,仅需要包含的lib为:
debug版:libboost_system-vc80-mt-gd-1_55.lib等一系列包含gd的库。
release版本:libboost_system-vc80-mt-1_55.lib等一系列不包含gd的库。
使用动态库链接:
[cpp] view plain print?
#define BOOST_ALL_DYN_LINK
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
使用动态库链接时,仅需要包含的lib为:
debug版:boost_system-vc80-mt-gd-1_55.lib,同时在生成的exe加入boost_system-vc80-mt-gd-1_55.dll
release版:boost_system-vc80-mt-1_55.lib,同时在生产的exe路径下加入boost_system-vc80-mt-1_55.dll
㈦ win7下vs2010编译boost怎么配置stlport
一、安装cmake
1、这一步比较简单,下载安装最新版本cmake-2.8,开始如下安装
2、注意这里选择第二个选项,为所有的用户添加系统变量
3、选择安装到目录 F:\CMake 2.8,个人建议最好安装在C盘目录下。
4、安装完毕后确认一下系统变量中有没有红色框中的目录,若没有需要手动添加进去。
5、cmake安装完毕!
二、安装Boost库
1、下载最新版本,当前为boost_1_55_0
2、按 Win+R组合键输入cmd进入命令窗口:
切换当前目录为boost的安装目录(G:\boost_1_55_0),输入bootstrap.bat
3、执行完上述命令后会在安装目录下生成如下exe文件
4、继续在DOS窗口中输入bjam.exe,程序会根据你当前安装的编译环境(vs2010,vs2012,vs2013)等自动选择与之相适应的库文件和包含文件等。
此过程大概需要20分钟左右。根据下面第二个图片可以算出我的编译环境为MSVC-12.0即VS2013.
5、20分钟左右后可以看到如下界面,说明Boost库配置完成
三、安装CGAL
1、下载CGAL,这里我下载的是CGAL-4.4这个版本(当前最新的)
2、安装位数选择32位
如果选择64位进行安装,则会在以后配置完毕后出现类似“无法识别的外部符号。。。”等问题,很难进行正确配置。所以这里最好全部选择32位进行安装。
3、安装目录我选择C:\Program Files\CGAL-4.4
安装在其他目录时可能会出现用Cmake编译时出现好几外错误。可以尝试通过安装在C盘进行解决。
4、选择如下几项,单击下一步
5、安装完成后可能会出现如下提示,则需要手动添加F:\CGAL-4.4\auxiliary\gmp\lib到Path变量中
6、此时CGAL安装完成
四、用Cmake配置CGAL库
1、打开Cmake软件选择如下目录,注:两个目录是相同的
2、单击“config"-选择如下编译器(默认是32位,与前面安装软件一定要保持一致)
3、单击确定后,出现如下界面说明配置成功
4、找到如下图的这一项,选中,再次单击"config"进行配置
5、单击Generate,此时界面应如下。
6、此时在CGAL安装目录下出现如下文件:CGAL.sln
7、打开此文件,此时编译器会自动组建一个解决方案。如下图
8、选择32位debug模式,按F7进行编译,编译完成后如下图所示,表明CGAL至此完全配置成功。
五、举例测试CGAL
新建一个控制台应用程序,并添加如下代码
#include <iostream>
#include <boost/format.hpp>
#include <QtGui>
#include <CGAL/Qt/GraphicsViewNavigation.h>
#include <QLineF>
#include <QRectF>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setSceneRect(0,0, 100, 100);
scene.addRect(QRectF(0,0, 100, 100), QPen(QColor(255,0,0)));
scene.addLine(QLineF(0,0, 100, 100));
scene.addLine(QLineF(0,100, 100, 0));
QGraphicsView* view = new QGraphicsView(&scene);
CGAL::Qt::GraphicsViewNavigation navigation;
view->installEventFilter(&navigation);
view->viewport()->installEventFilter(&navigation);
view->setRenderHint(QPainter::Antialiasing);
view->show();
return app.exec();
}
添加包含库目录,操作如下图,注意红色框中的添加内容
添加附加库目录,操作如下图,注意红色框中的添加内容
㈧ VS2012+Windows下使用Boost的thread库编译报错
同问,我也遇到了,有解决办法吗?
boost库编译成动态链接库就可以了。boost库有3种编译状态,看哪种和调用程序匹配。
㈨ windows下boost怎样安装与使用说明
一、 下载boost
boost_1_51_0.zip 下载并解压到C盘根文件夹
二、编译boost
1、生成生命行程序
执行bootstrap.bat
2、编译
执行b2.exe,完成后显示:
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
C:/boost_1_51_0
The following directory should be added to linker library paths:
C:\boost_1_51_0\stage\lib
三、使用boost
1、创建一个win32 console
2、引用bootst
C/C++ -> Additional Include Directories: C:\boost_1_51_0
Linker-> Additional Library Directories: C:\boost_1_51_0\stage\lib
Linker->Input->Additional Dependencies :libboost_signals-vc110-mt-gd-1_51.lib;libboost_regex-vc110-mt-gd-1_51.lib;
3、Code如下:
#include "stdafx.h"
#include <boost/regex.hpp>
#include <boost/signals.hpp>
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <cassert>
struct print_sum {
void operator()(int x, int y) const { std::cout << x+y << std::endl; }
};
struct print_proct {
void operator()(int x, int y) const { std::cout << x*y << std::endl; }
};
int _tmain(int argc, _TCHAR* argv[])
{
boost::signal2<void, int, int, boost::last_value<void>, std::string> sig;
sig.connect(print_sum());
sig.connect(print_proct());
sig(3, 5);
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
return 0;
}
示例程序在vs2012下通过,输出:
8
15
㈩ boost源码如何应用
下载Boost库,这里我选择下载boost_1_55_0.zip
解压boost文件到本地目录(如G:\boost_1_55_0),可以发现解压后的文件中有一个bootstrap.bat文件。
然后以管理员身份打开cmd窗口,
上述命令执行完毕后可以发现G:\boost_1_55_0下新生成了一个bjam.exe文件
在命令窗口中输入语句:bjam.exe
此过程将默认根据系统已经安装好的编译工具(VS2008,2010,2012,2013)等编译相应的Lib文件、头文件等。(此步骤大概需要10分钟)
可以看到msvc 12.0,这是因为我系统中已经安装过了VS2013
msvc : 8.0是VS2005
msvc : 10.0是VS2010
msvc : 12.0是VS2012、VS2013
第5步执行成功后会有如下信息提示
至此我们已经完成了boost库的安装,下面需要配置一下VS2013了。新建一个VS2013控制台应用程序(工程名为boostest),添加如下代码
#include "stdafx.h"
#include <boost/lexical_cast.hpp>
#include <iostream>
using namespace std;
int main()
{
using boost::lexical_cast;
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("123.0123456789");
string s0 = lexical_cast<string>(a);
string s1 = lexical_cast<string>(b);
cout << "number: " << a << " " << b << endl;
cout << "string: " << s0 << " " << s1 << endl;
int c = 0;
try{
c = lexical_cast<int>("abcd");
}
catch (boost::bad_lexical_cast& e){
cout << e.what() << endl;
}
return 0;
}
添加boostest工程的包含目录和库目录
包含目录添加 G:\boost_1_55_0
库目录添加 G:\boost_1_55_0\stage\lib
进入代码窗口编译并成功运行说明BOOST库确实已经配置成功,可以放心使用。