c++ 学习笔记(0) boost 环境搭建

本文详细介绍了在CentOS系统中从Gitee获取Boost源码,进行版本控制、编译和安装的过程,包括使用`bootstrap.sh`配置和`b2`构建,以及通过一个简单的Boost Timer示例验证安装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0 .获得boost 源码 并且编译 安装

[jeason@centos7 ~]$ git clone https://gitee.com/add358/boost.git
Cloning into 'boost'...
remote: Enumerating objects: 97421, done.
remote: Total 97421 (delta 0), reused 0 (delta 0), pack-reused 97421
Receiving objects: 100% (97421/97421), 173.74 MiB | 8.07 MiB/s, done.
Resolving deltas: 100% (51972/51972), done.
[jeason@centos7 ~]$ cd boost/
[jeason@centos7 boost]$ git tag
1.71.0
[jeason@centos7 boost]$ git checkout 1.71.0
Note: checking out '1.71.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at ab8d0ff2c... version 1.71.0
[jeason@centos7 boost]$ ls
boost            boostcpp.jam  boost.png      bootstrap.sh  index.htm   INSTALL  libs             more       rst.css  tools
boost-build.jam  boost.css     bootstrap.bat  doc           index.html  Jamroot  LICENSE_1_0.txt  README.md  status   version
[jeason@centos7 boost]$ ./bootstrap.sh
Building Boost.Build engine with toolset gcc... tools/build/src/engine/b2
Detecting Python version... 2.7
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... /usr
Generating Boost.Build configuration in project-config.jam for gcc...

Bootstrapping is done. To build, run:

    ./b2

To generate header files, run:

    ./b2 headers

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/build/

[jeason@centos7 boost]$ ./b2
Performing configuration checks

    - default address-model    : 64-bit
    - default architecture     : x86

Building the Boost C++ Libraries.
# 注意 这里开始进行代码的编译 依据不同的主机的性能去进行评定 我在服务器上编译大约不到2分钟 ?
*********************************************************************************************************
gcc.compile.c++ bin.v2/libs/wave/build/gcc-4.8.5/release/link-static/threading-multi/visibility-hidden/instantiate_re2c_lexer.o
gcc.archive bin.v2/libs/wave/build/gcc-4.8.5/release/link-static/threadapi-pthread/threading-multi/visibility-hidden/libboost_wave.a
common.copy /home/jeason/boost/stage/lib/libboost_wave.a
...updated 1380 targets...


The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    /home/jeason/boost

The following directory should be added to linker library paths:

    /home/jeason/boost/stage/lib

[jeason@centos7 boost]$
[jeason@centos7 boost]$ sudo ./b2 install
Performing configuration checks

    - default address-model    : 64-bit (cached)
    - default architecture     : x86 (cached)
    - symlinks supported       : yes (cached)
    - C++11 mutex              : no  (cached)
    - lockfree boost::atomic_flag : yes (cached)
    - Boost.Config Feature Check: cxx11_auto_declarations : no  (cached)
    - Boost.Config Feature Check: cxx11_constexpr : no  (cached)
    - Boost.Config Feature Check: cxx11_defaulted_functions : no  (cached)
    - Boost.Config Feature Check: cxx11_final : no  (cached)
    - Boost.Config Feature Check: cxx11_hdr_mutex : no  (cached)
    - Boost.Config Feature Check: cxx11_hdr_tuple : no  (cached)
    - Boost.Config Feature Check: cxx11_lambdas : no  (cached)
    - Boost.Config Feature Check: cxx11_noexcept : no  (cached)
    - Boost.Config Feature Check: cxx11_nullptr : no  (cached)
    - Boost.Config Feature Check: cxx11_rvalue_references : no  (cached)
    - Boost.Config Feature Check: cxx11_template_aliases : no  (cached)
    - Boost.Config Feature Check: cxx11_thread_local : no  (cached)
    - Boost.Config Feature Check: cxx11_variadic_templates : no  (cached)
    - has_icu builds           : yes (cached)

# *************************** 忽略 中间的打印
common.copy /usr/local/include/boost/compatibility/cpp_c_headers/csetjmp
common.copy /usr/local/include/boost/compatibility/cpp_c_headers/csignal
common.copy /usr/local/include/boost/compatibility/cpp_c_headers/cmath
common.copy /usr/local/include/boost/compatibility/cpp_c_headers/clocale
common.copy /usr/local/include/boost/compatibility/cpp_c_headers/climits
common.copy /usr/local/include/boost/compatibility/cpp_c_headers/cfloat
common.copy /usr/local/include/boost/compatibility/cpp_c_headers/cerrno
common.copy /usr/local/include/boost/compatibility/cpp_c_headers/cctype
common.copy /usr/local/include/boost/compatibility/cpp_c_headers/cassert
...updated 16211 targets...

1. 简单的测试

#include <boost/timer/timer.hpp>
#include <iostream>

using namespace boost;
int main()
{
    timer t;
    std::cout << t.elapsed_max() <<std::endl;
    return 0;
}
[jeason@centos7 ~]$ g++ test.cpp
In file included from test.cpp:1:0:
/usr/local/include/boost/timer.hpp:21:98: note: #pragma message: This header is deprecated. Use the facilities in <boost/timer/timer.hpp> instead.
 BOOST_HEADER_DEPRECATED( "the facilities in <boost/timer/timer.hpp>" )                               
[jeason@centos7 ~]$ ./a.out
9.22337e+12
[jeason@centos7 ~]$ rm a.out

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值