`
cyber4cn
  • 浏览: 38886 次
社区版块
存档分类
最新评论

boost的简单编译过程:

阅读更多
boost的简单编译过程:
从 boost 的官方网址 http://www.boost.org/ 下载 bz2、zip、7z 等格式的源码发布包。最新的发布版是 1.43.0 (May 6th, 2010)。
酱子解压 bz2 包(嫌输出诊断文本烦的话,把 -v 去掉或 > file.log):
tar -xvjf boost_[ver].tar.bz2
Boost Getting Started Guide
Boost Getting Started Guide
Boost Getting Started on Windows
Header-Only Libraries
boost 中有些库是不需要编译成独立的库文件的,所有的特性都在头文件中实现,叫做 header-only lib,比如:lambda。这时只要 include boost 的头文件就可以了,例子:
查看源代码
打印帮助
01	#include <boost/lambda/lambda.hpp>
02	#include <iostream>
03	#include <iterator>
04	#include <algorithm>
05	 
06	int main()
07	{
08	    using namespace boost::lambda;
09	    typedef std::istream_iterator<int> in;
10	 
11	    std::for_each(
12	        in(std::cin), in(), std::cout << (_1 * 3) << " " );
13	}

用 gcc 的 -I 选项指定头文件的搜索路径。
必需独立编译的库有:
Boost.Filesystem
Boost.IOStreams
Boost.ProgramOptions
Boost.Python (see the Boost.Python build documentation before building and installing it)
Boost.Regex
Boost.Serialization
Boost.Signals
Boost.System
Boost.Thread
Boost.Wave
有些库可以编译也可以 header-only 方式使用,视你使用的特性而定:
Boost.DateTime has a binary component that is only needed if you're using its to_string/from_string or serialization features, or if you're targeting Visual C++ 6.x or Borland.
Boost.Graph also has a binary component that is only needed if you intend to parse GraphViz files.
Boost.Test can be used in “header-only” or “separately compiled” mode, although separate compilation is recommended for serious use.
上述库都可以在 Getting Started 上找到链接。
编译 boost 库
需要独立编译的 boost 库叫做 separately-compiled lib。
通常使用一个叫 bjam 的配置管理工具来编译 boost,就像是 make。在 这里 去找 bjam 的信息。
确定你的编译工具集(Toolset),比如 msvc、gcc 等。这里 有完整的工具集列表。对于 gcc,boost 的 bjam 支持 Cygwin 和 MinGW 两种主流的发行版。
我用gcc 编译,从 bash 进入到 boost 的源码目录下,运行 bootstrap.sh,然后再运行 ./bjam 就完成编译了,注意:一定要使用 boost 目录下由 bootstrap.sh 生成的 bjam,而不是从网上下载的已编译好的 bjam。如果你想指定编译选项,或选择性的指定要编译的 boost 特性库,可以用 bootstrap.sh --help 查看有哪些选项。如下:
查看源代码
打印帮助
1 $ cd /path/to/boost
2 $ ./bootstrap.sh --help
3 (一堆帮助)
4
5 $ ./bootstrap.sh
6 $ ./bjam stage
stage 方式指编译后把库(.a、.dll)放到 boost 源码包的目录下(默认在 stage/lib 下),不进行向安装目录的头文件和库文件的拷贝,与 stage 方式相对的是 install 方式。
有一些编译选项控制生成库的 debug/release 和 static/shared 编译方式,在文档中称为 build variants of the lib。和这些相关的选项有:variant=debug|release,link=static|shared,runtime- link=static|shared,--build-type=minimal|complete 等,详细的说明参考 bjam --help
用 bjam 的 --show-libraries 显示支持编译的特性库,用 --with-library-name 和 --without-library-name 定制编译的特性库。
默认的编译过程很慢,请耐心等待……
boost 库的命名规范
生成的 boost 库有一定的命名规范,来表示它的编译特征,如:静态/动态,调试版/发布版,编译使用的工具集等,详见:Library Naming。如下:
In order to choose the right binary for your build configuration you need to know how Boost binaries are named. Each library filename is composed of a common sequence of elements that describe how it was built. For example, libboost_regex-vc71-mt-d-1_34.lib can be broken down into the following elements:
lib
Prefix: except on Microsoft Windows, every Boost library name begins with this string. On Windows, only ordinary static libraries use the lib prefix; import libraries and DLLs do not.
boost_regex
Library name: all boost library filenames begin with boost_.
-vc71
Toolset tag: identifies the toolset and version used to build the binary.
-mt
Threading tag: indicates that the library was built with multithreading support enabled. Libraries built without multithreading support can be identified by the absence of -mt.
-d
ABI tag: encodes details that affect the library's interoperability with other compiled code. For each such feature, a single letter is added to the tag:
s: linking statically to the C++ standard library and compiler runtime support libraries.
g: using debug versions of the standard and runtime support libraries.
y: using a special debug build of Python.
d: building a debug version of your code.
p: using the STLPort standard library rather than the default one supplied with your compiler.
n: using STLPort's deprecated "native iostreams" feature.
For example, if you build a debug version of your code for use with debug versions of the static runtime library and the STLPort standard library in “native iostreams” mode, the tag would be: -sgdpn. If none of the above apply, the ABI tag is ommitted.
-1_34
Version tag: the full Boost release number, with periods replaced by underscores. For example, version 1.31.1 would be tagged as "-1_31_1".
.lib
Extension: determined according to the operating system's usual convention. On most unix-style platforms the extensions are .a and .so for static libraries (archives) and shared libraries, respectively. On Windows, .dll indicates a shared library and .lib indicates a static or import library. Where supported by toolsets on unix variants, a full version extension is added (e.g. ".so.1.34") and a symbolic link to the library file, named without the trailing version number, will also be created.

使用、链接 boost 库
要参考 Getting Started on Unix Variants 的 Link Your Program to a Boost Library,而不是 Windows 的。
示例代码,用到了 Boost.Regex 特性库:
查看源代码
打印帮助
01	#include <boost/regex.hpp>
02	#include <iostream>
03	#include <string>
04	 
05	int main()
06	{
07	    std::string line;
08	    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
09	 
10	    while (std::cin)
11	    {
12	        std::getline(std::cin, line);
13	        boost::smatch matches;
14	        if (boost::regex_match(line, matches, pat))
15	            std::cout << matches[2] << std::endl;
16	    }
17	}

像酱子设定编译、链接选项:
查看源代码
打印帮助
1 g++ -o foo.exe -I/path/to/boost -L/path/to/boost/stage/lib -lboost_regex foo.cpp
-l 指定库名字时,去掉前缀 lib 和后缀 .a/.lib。gcc 会自动选择 static 或 shared (dynamic) 的库,比如:在 stage/lib 中有两套 boost.regex 的库,静态库 libboost_regex.a,动态库和其导入库 cygboost_regex.dll/libboost_regex.dll.a,如果仅指定 -lboost_regex,gcc 会链接到动态库 cygboost_regex.dll 上,这时在运行客户程序时需要动态库 cygboost_regex.dll 能被 Windows 加载器找到(当前目录、System32、PATH 目录等搜索顺序)。如果要链接静态库,需要使用 -static 选项,试验后发现仅使用这个选项不行,它会强制链接 gcc 的 RT 静态库,然后提示 cannot find -lgcc_s,不过可以不使用 -L/-l 自动搜索库选项,而是直接在链接选项中输入静态库 libboost_regex.a 的全路径来完成 boost 静态库的链接。
测试例子:
To: George Shmidlap
From: Rita Marlowe
Subject: Will Success Spoil Rock Hunter?
---
See subject.
上面文本保存为 test.mail,然后运行我们的程序 foo.exe:./foo.exe < test.mail。OK,boost.regex 将会抽出 subject 的文本并打印出来。

原文
http://hi.baidu.com/jzinfo/blog/item/ae41d73924fd03fa3b87cefd.html


安装别的软件时遇到两个问题:
一、 error: 'class  boost::filesystem3::directory_entry' has no member named 'leaf'

解决办法:
If there's a lot of problems like this, compile with

-DBOOST_FILESYSTEM_VERSION=2 and have upstream decide what to do

long-term.  In this particular case, you should be able to replace

leaf() with path().filename().string().


二、老是连接不成功。link error  修改 /etc/ld.so.conf
分享到:
评论

相关推荐

    boost_1_78_0编译及使用

    这将创建一个名为`bjam`或`b2`的可执行文件,用于后续的编译过程。 3. **选择编译组件**: Boost包含众多组件,你可能不需要全部编译。可以使用`--with-modules`选项指定要编译的模块,例如,如果你只需要`date_time...

    bjam.exe boost库编译使用的工具

    BJAM.exe 和 B2.exe 是 Boost 库编译过程中使用的两个关键工具,它们都是 Boost.Build 系统的一部分,用于自动化构建 Boost 库的过程。Boost 库是一个广泛使用的开源 C++ 库集合,提供了大量功能丰富的模块,如线程...

    boost编译工具 C++

    BJAM简化了库的配置和编译过程,使得开发者能够在不同的平台上方便地构建Boost库。 BJAM是Boost库的一部分,它基于Jam工具,一个类似Make的构建工具。BJAM可以处理复杂的依赖关系,支持多平台和多编译器,允许用户...

    arm架构下的boost库文件

    本文将详细介绍Boost库在ARM架构下的编译过程以及如何在项目中应用。 首先,让我们了解一下Boost库的主要特点和组件: 1. **多线程支持**:Boost.Thread库提供了线程管理和同步原语,如互斥量、条件变量和future/...

    Ubuntu安装boost加测试程序

    在编译过程中,可能会遇到**错误和问题**。常见的问题可能是编译器不兼容或者缺少依赖。如果遇到错误,仔细阅读错误信息,查找解决方案。例如,如果缺少某些开发库,可以使用`apt-get`安装,如`libpthread-dev`或`...

    C++ boost开发教程

    根据给定文件的信息来看,似乎...无论是进行网络编程、多线程处理还是简单的文件操作,Boost都能提供高效且易于使用的解决方案。希望本文能够帮助读者更好地理解和应用Boost库,从而在软件开发过程中取得更好的成果。

    centOS 安装boost1.68.0库

    如果你希望直接安装Boost库而跳过编译过程,可以使用以下命令: ``` ./b2 install ``` 或者使用`bjam`命令: ``` ./bjam install ``` 安装完成后,Boost的头文件将被放置在`/usr/local/include/`目录下,而库文件则...

    boost_1_59_0-msvc-14.0-32.rar

    通常,手动编译Boost可能涉及多个步骤,包括下载源码、配置环境、选择编译选项等,这可能会对开发过程造成一定的困扰。 在32位系统中,动态库(dll)和静态库(lib)各有优缺点。动态库可以减少应用程序的大小,...

    boost python 1.49 编译的库文件

    总的来说,Boost.Python是一个强大的工具,使得C++和Python之间的互操作变得简单而高效。在VS2008和Python 2.6的环境中,这些编译好的库文件可以让你快速地开始开发混合语言的应用程序。记得在使用时根据你的项目...

    boost1.6 64位 windows 安装版本 不用编译

    对于Windows用户来说,尤其是那些不熟悉或不想进行编译过程的开发者,预编译的安装版本是一个理想的选择。 “boost_1_66_0-msvc-12.0-64.exe”是Boost 1.66.0版本针对Microsoft Visual Studio 2013(MSVC 12.0)的...

    C++中文版网络编程boost asio.docx

    - **定义**:Boost Asio 是一个跨平台的 C++ 库,它提供了一种简单且统一的方式来访问底层网络编程接口。 - **目标**:简化网络编程过程,支持同步和异步操作,适用于多种平台(如 Windows 和 POSIX 系统)。 #####...

    C++实现Telnet客户端源码

    在VS2015下编译这个项目时,需要注意Boost库的路径配置。通常,我们需要将Boost库的头文件目录添加到包含路径(Include Directories),将库文件目录添加到库路径(Library Directories),并且链接相应的Boost库...

    boost简易教程.doc

    5. 编译过程完成后,Boost库会生成在`stage\lib`目录下。 **配置Visual Studio** 1. 打开VS2013,创建一个新的C++项目。 2. 在项目的属性页中,导航到“配置属性”&gt; “C/C++” &gt; “常规”,然后在“附加包含目录...

    linux下编译boost.python简单方法

    4. **解决编译错误**:如果在编译过程中遇到“Nobestalternativefor/python_for_extensions”这类错误,这可能是由于存在多个Python版本造成的。此时,确保所有使用的Python版本都是正确的,并且正确指定了版本路径...

    boost 安装包

    6. **测试安装**: 编写一个简单的C++程序,引入Boost库,如`#include &lt;boost/date_time.hpp&gt;`,然后尝试编译运行,确保Boost已成功安装并可被项目使用。 **常见问题与解决办法** 1. **编译错误**: 如果在编译Boost...

    boost库软件和安装说明

    你可以编写一个简单的C++程序,包含Boost库的头文件,然后编译运行以验证安装是否成功。 以上步骤完成后,你就在Linux环境下成功安装了Boost库。接下来,你可以开始探索Boost的各种功能,如智能指针(smart ...

    C++Boost的Regex库用法

    Boost库的安装和编译过程较为复杂,需要下载源代码包,然后根据自己的开发环境进行编译和配置。编译成功后,需要将生成的库文件和头文件目录添加到项目的链接器设置和包含路径中,这样才能在项目中使用Boost Regex库...

Global site tag (gtag.js) - Google Analytics