CodeBlocks使用boost+MinGW

一:安裝MinGWios

一、下載MinGWide

二、安裝MinGW,在系統變量中添加一個MingG_home, 值爲MinGW的路徑,並在 「PATH」 中添加 %MinG_home%\bin;測試

三、測試:在cmd下,輸入gcc -v,會顯示版本信息ui

2、用MinGW編譯boost,其實boost的大部分的庫不用編譯,可直接使用,可是少部分的庫仍是須要編譯。如threadspa

  一、在dos界面下(cmd),進入boost的解壓目錄code

  二、bootstarp.batblog

  三、bjam --toolset=gcc --build-type=complete --with-thread stagecmd

    注:能夠使用bjam --show-libraries查看全部的庫,如須要編譯其它的庫,將上面命令中的thread更改成相應的名字便可。it

3、在CodeBlock中,添加boost庫(這個讓我糾結了好久)io

  一、Settings-->Global Variable-->Current Variable-->"New"-->輸入「boost」(名字);

    base:   輸入boost的根目錄

    include: 輸入boost的根目錄,這個實際上是相對的,反正咱們須要保證的是 該目錄下有boost這個目錄就行。

    lib:       編譯後的庫目錄,即xxx\boostxx\stage\lib

  二、你的工程-->右鍵-->"build-options"-->"Search diectories":

    compiler: add -->  $(#boost.include)

    link:    add -->  $(#boost.lib)   (便是引用全局變量)

  三、你的工程-->右鍵-->"build-options"-->Linker Settings-->Link Libraries-->add-->    $(#boost.lib)\*   

    (表示將全部的庫都加進去)

    

  測試代碼:

  

 1 #include <iostream>
 2 #include <boost/thread.hpp>
 3 using namespace std;
 4 
 5 void hello()
 6 {
 7     cout <<"Hello world, I'm athread!"<< endl;
 8 }
 9 
10 int main()
11 {
12     boost::thread thread(&hello);
13     thread.join();
14     return 0;
15 }
View Code
相關文章
相關標籤/搜索