(CodeBlocks+MingW)安装和使用Boost

来源:互联网 发布:中国移动app 软件下载 编辑:程序博客网 时间:2024/05/16 08:53

原文链接


目录(?)[+]

第一步

是下载codeblocks-12.11mingw-setup.exe,下载地址::

http://www.codeblocks.org/downloads/26.然后安装CodeBlocks.

第二步

下载Boost,然后解压到一个目录.可以到Boost网站(http://www.boost.org/)下载最新的版本.

例如:

我下载的是boost_1_52_0.7z.解压到目录:D:\ProgramFiles\boost_1_52_0:

 

第三步

1、编译Boost.打开控制台,进入目录D:\ProgramFiles\boost_1_52_0:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. cd  D:\ProgramFiles\boost_1_52_0  

2、然后生成bjam.exe和b2.exe文件:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. bootstrap.bat gcc    

3、[不使用Python的可忽略这步]下面的方法可以使用python库:

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. 修改D:\ProgramFiles\boost_1_52_0\tools\build\v2\user-config.jam最后一行即可    
  2. using python : 2.7 : C:/Python27 : C:/Python27/include : C:/Python27/Libs ;    
  3. 注意 : 和 ; 都是使用空格分开的,空格不能省略,且路径不能使用\,一定要使用/才行.   

4、然后在控制台编译Boost并安装Boost到目录D:\ProgramFiles\boost:

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. .\b2 --toolset=gcc --prefix=D:\ProgramFiles\boost install  
或者使用

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. .\bjam --prefix=D:\ProgramFiles\boost\ --build-type=complete --toolset=gcc install  
漫长等待后就可以了.

如果运行此命令出现错误

Unable to load Boost.Build: could not find "boost-build.jam"

那通常是控制台当前工作目录(D:\ProgramFiles\boost_1_52_0)不对,新手常犯错.

编译完成后下面的目录会被自动创建:

cpp头文件夹:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. D:\ProgramFiles\boost\include\boost-1_52\boost\.....  

库文件夹::

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. D:\ProgramFiles\boost\lib\......  

第四步

在Codeblocks中使用Boost.定义全局变量boost,注意base,include和lib的填写,

设置 Code::Blocks中的全局变量boost
Setting->Global Variables         
i.  单击New按钮,创建boost全局变量
ii. 设置 base: D:\ProgramFiles\boost\
iii.设置include:D:\ProgramFiles\boost\include\boost-1_52
iv.设置lib: D:\ProgramFiles\boost\lib\

如图所示:

 

第五步

设置编译器,如图所示:

Search directories tab Compiler sub-tab filed entered$(#boost.include)

 

设置Linker选项

Search directories tab Linker sub-tab filed entered$(#boost.lib)

第六步 测试boost程序

下面是个测试程序testboost.cpp,文件格式最好保存为UTF8,这样中文识别会好一点:

[cpp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. #include <boost/lambda/lambda.hpp>  
  2. #include <iostream>  
  3. #include <iterator>  
  4. #include <algorithm>  
  5.   
  6. int main()  
  7. {  
  8.     using namespace boost::lambda;  
  9.     typedef std::istream_iterator<int> in;  
  10.   
  11.     std::cout<<"测试开始,请输入字符:"<<std::endl;  
  12.   
  13.     std::for_each(  
  14.         in(std::cin), in(), std::cout << (_1 * 3) << " " );  
  15.   
  16.     std::cout<<"测试完毕!"<<std::endl;  
  17.   
  18.     return 0;  
  19. }  


OK,一切完毕,正常!

关于b2和bjam的用法如下:

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. Boost.Build 2011.12-svn  
  2.   
  3. Project-specific help:  
  4.   
  5.   Project has jamfile at Jamroot  
  6.   
  7. Usage:  
  8.   
  9.   bjam [options] [properties] [install|stage]  
  10.   
  11.   Builds and installs Boost.  
  12.   
  13. Targets and Related Options:  
  14.   
  15.   install                 Install headers and compiled library files to the  
  16.   =======                 configured locations (below).  
  17.   
  18.   --prefix=<PREFIX>       Install architecture independent files here.  
  19.                           Default; C:\Boost on Win32  
  20.                           Default; /usr/local on Unix. Linux, etc.  
  21.   
  22.   --exec-prefix=<EPREFIX> Install architecture dependent files here.  
  23.                           Default; <PREFIX>  
  24.   
  25.   --libdir=<DIR>          Install library files here.  
  26.                           Default; <EPREFIX>/lib  
  27.   
  28.   --includedir=<HDRDIR>   Install header files here.  
  29.                           Default; <PREFIX>/include  
  30.   
  31.   stage                   Build and install only compiled library files  
  32.   =====                   to the stage directory.  
  33.   
  34.   --stagedir=<STAGEDIR>   Install library files here  
  35.                           Default; ./stage  
  36.   
  37. Other Options:  
  38.   
  39.   --build-type=<type>     Build the specified pre-defined set of variations  
  40.                           of the libraries. Note, that which variants get  
  41.                           built depends on what each library supports.  
  42.   
  43.                               minimal (default) - Builds a minimal set of   
  44.                               variants. On Windows, these are static   
  45.                               multithreaded libraries in debug and release  
  46.                               modes, using shared runtime. On Linux, these  
  47.                               are static and shared multithreaded libraries  
  48.                               in release mode.  
  49.   
  50.                               complete - Build all possible variations.  
  51.   
  52.   --build-dir=DIR         Build in this location instead of building  
  53.                           within the distribution tree. Recommended!  
  54.   
  55.   --show-libraries        Displays the list of Boost libraries that require  
  56.                           build and installation steps, then exit.  
  57.   
  58.   --layout=<layout>       Determines whether to choose library names  
  59.                           and header locations such that multiple  
  60.                           versions of Boost or multiple compilers can  
  61.                           be used on the same system.  
  62.   
  63.                               versioned - Names of boost binaries  
  64.                               include the Boost version number, name and  
  65.                               version of the compiler and encoded build  
  66.                               properties.  Boost headers are installed in a  
  67.                               subdirectory of <HDRDIR> whose name contains  
  68.                               the Boost version number.  
  69.   
  70.                               tagged -- Names of boost binaries include the  
  71.                               encoded build properties such as variant and  
  72.                               threading, but do not including compiler name  
  73.                               and version, or Boost version. This option is  
  74.                               useful if you build several variants of Boost,  
  75.                               using the same compiler.  
  76.   
  77.                               system - Binaries names do not include the  
  78.                               Boost version number or the name and version  
  79.                               number of the compiler.  Boost headers are  
  80.                               installed directly into <HDRDIR>.  This option  
  81.                               is intended for system integrators who are  
  82.                               building distribution packages.  
  83.   
  84.                           The default value is 'versioned' on Windows, and  
  85.                           'system' on Unix.  
  86.   
  87.   --buildid=ID            Adds the specified ID to the name of built  
  88.                           libraries.  The default is to not add anything.  
  89.   
  90.   --python-buildid=ID     Adds the specified ID to the name of built  
  91.                           libraries that depend on Python.  The default   
  92.                           is to not add anything. This ID is added in   
  93.                           addition to --buildid.  
  94.   
  95.   
  96.   --help                  This message.  
  97.   
  98.   --with-<library>        Build and install the specified <library>  
  99.                           If this option is used, only libraries  
  100.                           specified using this option will be built.  
  101.   
  102.   --without-<library>     Do not build, stage, or install the specified  
  103.                           <library>. By default, all libraries are built.  
  104.   
  105. Properties:  
  106.   
  107.   toolset=toolset         Indicates the toolset to build with.  
  108.   
  109.   variant=debug|release   Select the build variant  
  110.   
  111.   link=static|shared      Whether to build static or shared libraries  
  112.   
  113.   threading=single|multi  Whether to build single or multithreaded binaries  
  114.   
  115.   runtime-link=static|shared        
  116.                           Whether to link to static or shared C and C++ runtime.  
  117.     
  118.   
  119. Configuration help:  
  120.   
  121.   Configuration file at E:\SoftWare\Boost_MinGW\boost_1_53_0\tools\build\v2  
  122.   user-config.jam  
  123.   
  124.   This file is used to configure your Boost.Build installation. You can modify  
  125. this file in place, or you can place it in a permanent location so that it  
  126. does not get overwritten should you get a new version of Boost.Build. See:  
  127.   
  128.   http://www.boost.org/boost-build2/doc/html/bbv2/overview/configuration.html  
  129.   
  130. for documentation about possible permanent locations.  
  131.   
  132. General command line usage:  
  133.   
  134.     bjam [options] [properties] [targets]  
  135.   
  136.   Options, properties and targets can be specified in any order.  
  137.         
  138. Important Options:  
  139.   
  140.   * --clean Remove targets instead of building  
  141.   * -a Rebuild everything  
  142.   * -n Don't execute the commands, only print them  
  143.   * -d+2 Show commands as they are executed  
  144.   * -d0 Supress all informational messages  
  145.   * -q Stop at first error  
  146.   * --debug-configuration Diagnose configuration  
  147.   * --debug-building Report which targets are built with what properties  
  148.   * --debug-generator Diagnose generator search/execution  
  149.   
  150. Further Help:  
  151.   
  152.   The following options can be used to obtain additional documentation.  
  153.   
  154.   * --help-options Print more obscure command line options.  
  155.   * --help-internal Boost.Build implementation details.  
  156.   * --help-doc-options Implementation details doc formatting.  
  157.   
  158. ...found 1 target...  


0 0
原创粉丝点击