【C++】win系统用MinGW编译Boost库

Boost官方入门汉化:https://www.cnblogs.com/yaoyu126/p/10186910.html
操作:https://zhuanlan.zhihu.com/p/332252333
参考:https://blog.csdn.net/lyang0303/article/details/121434166


在win端如果使用非VS编译器,则需要使用Boost.Build来创建自己的二进制文件。本文,主要记录win系统用MinGW编译Boost库的过程。

1、下载

boost下载并解压缩,下载链接:https://www.boost.org/users/history/

2、编译链接库

1)创建三个独立文件夹

#后期可以删除,安装Boost.Build
mkdir D:\boost_build
#后期可以删除,存放
mkdir D:\boost_1_76_0\build
#后期不可删除,存放库文件的
mkdir D:\boost

2)安装Boost.Build

cd D:\boost_1_76_0\tools\build
bootstrap.bat gcc
b2 install --prefix="D:\boost_build" --toolset=gcc

3)编译链接库

先将cd D:\boost_1_76_0\
cd D:\boost_1_76_0\
b2 --build-dir="D:\boost_1_76_0\build" --prefix="D:\boost" --toolset=gcc --build-type=complete stage

4) 删除

编译完成后,可以把D:\boost_build和D:\boost_1_76_0\build两个目录删掉,最终的boost库安装在D:\boost下面

3、链接库测试

gcc -I"D:\boost\include\boost-1_76" -L"D:\boost\lib"
INCLUDE += D:\process\boost_1_77_0
LIB += D:\process\boost_1_77_0\stage\lib
测试代码:

#include <iostream>
#include <string>
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>

using namespace boost;

void helloA() 
{ 
	std::cout << "I'm thread A !  --- Start " << std::endl; 
	sleep(10);
	std::cout << "I'm thread A !  --- OVER " << std::endl; 
}

void helloB() 
{ 
	std::cout << "I'm thread B !  --- Start " << std::endl; 
	sleep(10);
	std::cout << "I'm thread B !  --- OVER " << std::endl; 
}

int main(int argc, char *argv[])
{
	std::cout << "Hello world!" << std::endl;

	boost::thread thrdA(&helloA);
    boost::thread thrdB(&helloB);  
    thrdA.join();
    thrdB.join(); 
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

后厂村路蔡徐坤

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

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

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

打赏作者

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

抵扣说明:

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

余额充值