C++ win系統(tǒng)如何用MinGW編譯Boost庫
在win端如果使用非VS編譯器,則需要使用Boost.Build來創(chuàng)建自己的二進(jìn)制文件。
本文,主要記錄win系統(tǒng)用MinGW編譯Boost庫的過程。
1、下載
boost下載并解壓縮,下載鏈接:https://www.boost.org/users/history/
2、編譯鏈接庫
1)創(chuàng)建三個(gè)獨(dú)立文件夾
#后期可以刪除,安裝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兩個(gè)目錄刪掉,最終的boost庫安裝在D:\boost下面
3、鏈接庫測(cè)試
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
測(cè)試代碼:
#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();
}總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Qt信號(hào)與槽知識(shí)點(diǎn)總結(jié)歸納
信號(hào)和槽是一種高級(jí)接口,應(yīng)用于對(duì)象之間的通信,它是QT的核心特性,下面這篇文章主要給大家介紹了關(guān)于Qt信號(hào)與槽知識(shí)點(diǎn)總結(jié)歸納的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
C++實(shí)現(xiàn)LeetCode(51.N皇后問題)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(51.N皇后問題),本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07

