CodeBlocks使用boost+MinGW

一:安装MinGW

1、下载MinGW

2、安装MinGW,在系统变量中添加一个MingG_home, 值为MinGW的路径,并在 “PATH” 中添加 %MinG_home%\bin;

3、测试:在cmd下,输入gcc -v,会显示版本信息

二、用MinGW编译boost,其实boost的大部分的库不用编译,可直接使用,但是少部分的库还是需要编译。如thread

  1、在dos界面下(cmd),进入boost的解压目录

  2、bootstarp.bat

  3、bjam --toolset=gcc --build-type=complete --with-thread stage

    注:可以使用bjam --show-libraries查看所有的库,如需要编译其它的库,将上面命令中的thread更改为相应的名字即可。

三、在CodeBlock中,添加boost库(这个让我纠结了很久)

  1、Settings-->Global Variable-->Current Variable-->"New"-->输入“boost”(名字);

    base:   输入boost的根目录

    include: 输入boost的根目录,这个其实是相对的,反正我们需要保证的是 该目录下有boost这个目录就行。

    lib:       编译后的库目录,即xxx\boostxx\stage\lib

  2、你的工程-->右键-->"build-options"-->"Search diectories":

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

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

  3、你的工程-->右键-->"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

转载于:https://www.cnblogs.com/wang-can/p/3589710.html

猜你喜欢

转载自blog.csdn.net/weixin_33728268/article/details/94063663