Boost库boost_1_77_0版本 + Windows环境 + Gcc编译 + Vscode部署

Boost库boost_1_77_0版本 + Windows环境 + Gcc编译 + Vscode部署

1.gcc编译器安装:

选择cywin64,主要是下载方便,cygwin下载https://www.cygwin.com/

安装教程参照:https://blog.csdn.net/u010356768/article/details/90756742

cywin64主要是一个下载器,需要自己安装gdb,gcc,make,mingw64-gcc-core,mingw64-g++,binuntils,cmake等插件。

Cygwin64 Terminal 可在windows上模拟一个linux系统,方便windows开发一些linux程序的编译调试;

终端环境与linux一样,用户目录在 D:\cygwin64\home\xxxx ,Cygwin64 Terminal共享home目录。

在这里插入图片描述

添加C:\cygwin64\bin 到环境变量,cmd运行检查是否安装成功

C:\Users\liyang>cygcheck -c cygwin
Cygwin Package Information
Package              Version        Status
cygwin               3.3.2-1        OK
C:\Users\liyang>gcc --version
gcc (GCC) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\liyang>gdb --version
GNU gdb (GDB) (Cygwin 10.2-1) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
C:\Users\liyang>g++ --version
g++ (GCC) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2.Vscode安装部署

安装地址:https://code.visualstudio.com/Download

部署:

安装插件: C/C++ ,C/C++ Extension Pack,C/C++ Project Generator,Chinese (Simplified) ,C++ Intellisense

通过CTRL+SHIFT+P ,create c++ project可以创建一个C/C++ Project Generator的项目

在这里插入图片描述

在这里插入图片描述

launch.json、task.json 根据自己的项目情况进行调整;

task.json 中可以自行配置使用的编译器,由于这个项目模板生成了makefile,所以这里使用系统中的make指令(这里也可以使用mingw32-make)

3.boost库编译

完全参照boost库编译手册:
https://www.boost.org/doc/libs/1_77_0/more/getting_started/windows.html

cd D:\process\boost_1_77_0\tools\build
bootstrap.bat gcc
b2 install --prefix=D:\boost

需要先准备好Boost.Build环境,完成后将D:\boost\bin 加入环境变量

cd D:\process\boost_1_77_0
b2 --build-dir=D:\process\boost_1_77_0\build toolset=gcc --build-type=complete threading=multi --layout=versioned stage

ps : stage 只编译静态库、动态库, 需要导出的使用 install

b2 --build-dir=D:\process\boost_1_77_0\build toolset=gcc --build-type=complete threading=multi --layout=versioned --prefix=D:\boost install

生成库在stage/lib目录

在这里插入图片描述
在这里插入图片描述

4.项目工程中调用boost库

makefile中,添加boost库的路径,以及依赖库,例如:boost_thread-gcc11-mt-s-x64-1_77

# define lib directory
LIB		:= lib

# extension path
INCLUDE += D:\process\boost_1_77_0
LIB		+= D:\process\boost_1_77_0\stage\lib

# define library paths in addition to /usr/lib
#   if I wanted to include libraries not in /usr/lib I'd specify
#   their path using -Lpath, something like:
LFLAGS =-lboost_thread-gcc11-mt-s-x64-1_77
...

测试代码:

#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(); 
}
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值