当前位置:首页 » 编程软件 » 编译boost

编译boost

发布时间: 2022-01-08 08:57:49

1. linux下G++怎么编译使用Boost库的程序

首先把Boost库的头文件存放到/usr/include/boost/路径下,再把Lib文件存放到/usr/local/lib/boost/路径下。修改/etc/profile文件,在此文件中增加如下2个环境变量:

BOOST_INCLUDE=/usr/include/boost
export BOOST_INCLUDE

BOOST_LIB=/usr/local/lib/boost
export BOOST_LIB

写一个如下所示的cpp文件。
//samlpe.cpp
#include <iostream>
#include <string>
#include <boost/thread.hpp>

using namespace std;

void threadRoutine(void)
{
boost::xtime time;
time.nsec = 0;
time.sec = 20;
cout << "线程函数做一些事情" << endl;
boost::thread::sleep(time);
}

int main(void)
{
string str;
cout << "输入任意字符开始创建一个线程..." << endl;
cin >> str;
boost::thread t(&threadRoutine);
t.join();
cout << "输入任意字符结束运行..." << endl;
cin >> str;
return 0;
}

保存。使用g++编译,命令如下所示:

g++ -o samlpe.out samlpe.cpp -I$BOOST_INCLUDE -L$BOOST_LIB -lboost_thread-gcc-mt

其中-I参数指定Boost头文件路径,-L参数指定Boost库文件路径,-l参数指定使用线程库名。在我使用的这个版本Boost里,到/usr/local/lib/boost路径下,可以看到有关Boost线程库文件,比如:libboost_thread-gcc-mt.a等。注意在用-l参数指定库名时把磁盘文件名前面那个lib前缀去掉就可以了。

2. 为什么没有编译 boost

1、用它带的booststrap脚本生成b2、bjam
2、用b2、bjam生成lib
boost附带的文档一开始就是教你怎么安装编译boost。照着做就是了!

3. 安装了多个版本vs怎么编译boost

boost有些库是不用安装的,仅需包含头文件库就行了。
但是有些很爽的库(thread,regex)需要根据不同的系统做不同的调整,所以必须编译。
编译的流程很简单,如果是windows操作系统,首先找到那个booststrap.bat的东西,然后在控制台下运行它,它会生成bjam.exe,然后就可以通过bjam来编译boost库了,在命令行下输入bjam --help看选项。

如果嫌麻烦,可以一次将boost库需要编译的全部编译了,bjam --build-type=complete,生成库全在stage目录下。

4. 如何使用VS2017编译boost

Based on KindDragons answer I compiled Boost 1.63. For 64bit. Starting with Developer Command Prompt for VS 2017 RC

Run: bootstrap.bat

open project-config.jam Here is mine:

import option ;

using msvc : 14.0 : "c:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\VC\Tools\MSVC\14.10.24728\bin\HostX64\x64\cl.exe";

option.set keep-going : false ;

Run b2 toolset=msvc-14.0 address-model=64

5. 如何编译boost linux

linux平台下要编译安装除gcc和gcc-c++之外,还需要两个开发库:bzip2-devel 和python-devel,因此在安装前应该先保证这两个库已经安装:
#yum install gcc gcc-c++ bzip2 bzip2-devel bzip2-libs python-devel -y
然后是去官网下载源码包,按照如下步骤:
#tar xvzf boost_1_50_0.tar.gz
进入boost_1_50_0目录:
#cd boost_1_50_0
然后是编译安装,boost源码包中有配置脚本,直接用就可以:
#sh ./bootstrap.sh
Building Boost.Build engine with toolset gcc... tools/build/v2/engine/bin.linuxx86_64/b2
Detecting Python version... 2.6
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...
Bootstrapping is done. To build, run:
./b2
To adjust configuration, edit 'project-config.jam'.
Further information:
- Command line help:
./b2 --help
- Getting started guide:
http://www.boost.org/more/getting_started/unix-variants.html
- Boost.Build documentation:
http://www.boost.org/boost-build2/doc/html/index.html
接下来就是编译,重点关注是否编译成功:
#./b2

6. 如何编译boost.1.60库

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库。当然这件事情又一如既往很酷地没有出现在容易看到的地方。而是让你链接错误后再去玩抓虫游戏。

7. 如何编译&使用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

8. boost 在gcc 4.8环境完整编译出来后有多大

“完整”不知道,因为你用complete方式编译的话,它会连那些测试用例文件一起编译了。速度超——————超级慢。好几个小时要吧。总觉得干这种事很蛋疼……

如果只是编译库(lib,.a)的话,速度要快不少,指定debug或者release的话更快。

只是库我记得编译好以后它文件夹就有一两个G了。gcc编译出来的lib又比vc出来的更大,我这里VC出来1个G(包括编译过程中生成的obj文件和编译后生成的dll和lib,包含debug和release),我猜测备好2G空间是基本的。complete下,它不会再重新编译这些库,而是只是和主程序链接。总之猜测2.5个G到3个G

9. 为什么boost需要编译的库这么坑爹

,
2, 本编译程序同操作系统能使用目标系统重新编译源代码应该boost库种用文件式实现没依赖性实现库需要目标系统安装相应库文件才程序链接
3编写源代码编译器编译目标文件链接器链接执行文件VS傻瓜软件隐藏细节问题找

10. boost怎么编译

1、用它带的booststrap脚本生成b2、bjam
2、用b2、bjam生成lib

boost附带的文档一开始就是教你怎么安装编译boost。照着做就是了

热点内容
装缓存下载 发布:2024-09-20 05:42:36 浏览:72
gon引擎自动回收脚本 发布:2024-09-20 05:39:39 浏览:246
好医生连锁店密码多少 发布:2024-09-20 05:09:38 浏览:15
魔兽脚本代理 发布:2024-09-20 05:09:35 浏览:99
python登陆网页 发布:2024-09-20 05:08:39 浏览:758
安卓qq飞车如何转苹果 发布:2024-09-20 04:54:30 浏览:178
存储过程中in什么意思 发布:2024-09-20 04:24:20 浏览:315
php显示数据 发布:2024-09-20 03:48:38 浏览:501
源码安装软件 发布:2024-09-20 03:44:31 浏览:354
入门编程游戏的书 发布:2024-09-20 03:31:26 浏览:236