【C++网络编程—linux下boost库源码编译安装】

  • 先把Linux系统下的boost源码包boost_1_69_0.tar.gz拷贝到某一指定路径下,然后解压,如下:
root@iZ2ze4aqfcvyxgcvpjrj6iZ:~/software_installation$ ls
boost_1_69_0.tar.gz
root@iZ2ze4aqfcvyxgcvpjrj6iZ:~/software_installation$ tar -zxvf boost_1_69_0.tar.gz 
  • tar解压完成后,进入源码文件目录,查看内容:
root@iZ2ze4aqfcvyxgcvpjrj6iZ:~/software_installation$ ls
boost_1_69_0  boost_1_69_0.tar.gz
root@iZ2ze4aqfcvyxgcvpjrj6iZ:~/software_installation cd boost_1_69_0/
root@iZ2ze4aqfcvyxgcvpjrj6iZ:~/software_installation/boost_1_69_0$ ls
boost            boostcpp.jam  boost.png      bootstrap.sh  index.htm   INSTALL  libs             more     status
boost-build.jam  boost.css     bootstrap.bat  doc           index.html  Jamroot  LICENSE_1_0.txt  rst.css  tools
  • 运行bootstrap.sh工程编译构建程序,查看目录:
root@iZ2ze4aqfcvyxgcvpjrj6iZ:~/software_installation/boost_1_69_0$ ./bootstrap.sh 
Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
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/build/doc/html/index.html

root@iZ2ze4aqfcvyxgcvpjrj6iZ:~/software_installation/boost_1_69_0$ ls
b2     boost-build.jam  boost.png      bootstrap.sh  index.html  libs             project-config.jam  tools
bjam   boostcpp.jam     bootstrap.bat  doc           INSTALL     LICENSE_1_0.txt  rst.css
boost  boost.css        bootstrap.log  index.htm     Jamroot     more             status
  • 运行b2程序
root@iZ2ze4aqfcvyxgcvpjrj6iZ:~/software_installation/boost_1_69_0$ ./b2

编译完成后,会有如下打印:

The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/home/tony/package/boost_1_69_0
The following directory should be added to linker library paths:
/home/tony/package/boost_1_69_0/stage/lib
root@iZ2ze4aqfcvyxgcvpjrj6iZ:~/software_installation# ./b2 install

安装完成后,最后会有如下信息打印出来:

ln-UNIX /usr/local/lib/libboost_wave.so
common.copy /usr/local/lib/libboost_exception.a
common.copy /usr/local/lib/libboost_system.a
common.copy /usr/local/lib/libboost_chrono.a
common.copy /usr/local/lib/libboost_timer.a
common.copy /usr/local/lib/libboost_test_exec_monitor.a
...updated 14831 targets...
  • 验证安装boost是否成功

test.cpp

#include <iostream>
#include <boost/bind.hpp>
#include <string>
using namespace std;

class Hello
{
public:
	void say(string name) 
	{ cout << name << " say: hello world!" << endl; }
};

int main()
{
	Hello h;
	auto func = boost::bind(&Hello::say, &h, "小呆鸟");
	func();
	return 0;
}

执行命令

g++ -o test test.cpp -std=c++11
./test

'结果显示'
小呆鸟 say: hello world!

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小呆鸟_coding

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值