C++ win系统如何用MinGW编译Boost库
在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();
}总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
C++中CString string char* char 之间的字符转换(多种方法)
在写程序的时候,我们经常遇到各种各样的类型转换,比如 char* CString string 之间的互相转换,这里简单为大家介绍一下,需要的朋友可以参考下2017-09-09
Java C++ 算法题解拓展leetcode670最大交换示例
这篇文章主要介绍了Java C++算法题解拓展leetcode670最大交换示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-09-09
C/C++函数参数声明解析int fun() 与 int fun(void) 的区别讲解
C++中int fun()和int fun(void)的区别在于函数参数的声明方式,前者默认允许任意参数,而后者表示没有参数,通过清晰的实例源代码,详细解释了它们在函数声明和调用中的不同之处,这篇文章介绍了C/C++函数参数声明int fun()与int fun(void)的差异,需要的朋友可以参考下2024-01-01
嵌入式项目使用C语言结构体位段特性实现断言宏校验数据范围有效性的方法
今天小编就为大家分享一篇关于嵌入式项目使用C语言结构体位段特性实现断言宏校验数据范围有效性的方法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧2018-12-12


最新评论