zoukankan      html  css  js  c++  java
  • boost:asio编译

    参考:http://hi.baidu.com/need_for_dream/blog/item/c14a28086a504c33e92488b5.html

    环境: VS2010,

              boost1.38.0,解压缩后放在,D:/boost_1_38_0。

    編譯bjam(这个我没有试过,转过来以后参考)
    利用Visual Studio 2005 Command Prompt開啟DOS視窗,將目錄cd到C:/boost_1_34_1/tools/jam/src下,執行build.bat,然後會在C:/ boost_1_38_0/tools/jam/src/bin.ntx86/產生bjam.exe,將bjam.exe複製到c:/ boost_1_38_0/下

    1,编译。

       boost库大部分源文件是只有投文件,所以有很多库不用编译就可以使用。但是有些库是需要编译源码的。asio就需要编译。

       怎么去编译呢?在boost官方网站下载bjam.exe,放入boost源文件的根目录下面。因为asio依赖于其它的一些库,所以编译参数还有点复杂。然后在cmd下输入
    D:/boost_1_38_0>bjam --with-system --with-thread --with-date_time --with-regex -
    -with-serialization stage

      编译完成后就可以在boost_1_38_0/stage里面找到编译好的库文件。如果在编译的时候出现编译器方面的错误,可以尝试运行C:/Program Files/Microsoft Visual Studio 9.0/VC/vcvarsall.bat,自动设置编译环境。

     有时候你的系统上面可能装了几个版本的VS,那么怎么指定版本呢?

    D:/boost_1_38_0>bjam --without-python --toolset=msvc-10.0 --with-thread --with-date_time --with-regex -
    -with-serialization stage

    --without-python 表示不使用 python
    --toolset : 所使用compiler,Visual Studio 2010為msvc-10.0
    --prefix:指定編譯後library的安裝目錄

    接下来就是导入include目录boost根目录到vs中,导入编译后的lib文件目录stage/lib到lib路径中去。

    vs2010:右击project->properties->VC++ Directories. 将D:/boost_1_38_0加入到include directories中去,将D:/boost_1_38_0/stage/lib加入到Library Directories路径中去。

    2, 尝试第一个程序。

    把asio下面的文档中的第一个例子抄下来.

    [cpp] view plaincopy
     
    1. //  
    2. // timer.cpp  
    3. // ~~~~~~~~~  
    4. //  
    5. // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)  
    6. //  
    7. // Distributed under the Boost Software License, Version 1.0. (See accompanying  
    8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)  
    9. //  
    10.   
    11. #include <iostream>  
    12. #include <boost/asio.hpp>  
    13. #include <boost/date_time/posix_time/posix_time.hpp>  
    14.   
    15. int main()  
    16. {  
    17.   boost::asio::io_service io;  
    18.   
    19.   boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));  
    20.   t.wait();  
    21.   
    22.   std::cout << "Hello, world!/n";  
    23.   
    24.   return 0;  
    25. }  

    编译,报错!

    1>LINK : fatal error LNK1104: cannot open file 'libboost_system-vc100-mt-gd-1_38.lib'

    仔细一查,确实没有找到这个文件,怎么办?

    可能是没有编译debug文件,暂时也不知道编译的时候该添加哪个参数让它编译debug文件。于是将编译选项output改为release,再编译。

    编译出错。

    LINK : fatal error LNK1104: cannot open file 'libboost_regex-vc100-mt-1_38.lib'

    郁闷啊。

    怎么这么麻烦呢?

     网上google了一把,看到下面文字

    注意:

     

    使用MSVC或Borland C++,你可能需要在“工程设置”中分别添加 -DBOOST_DATE_TIME_NO_LIB 和-DBOOST_REGEX_NO_LIB 声明,分别禁止Boost.Date_Time和Boost.Regex的自动链接,当然你也可以这样做:build这两个库,然后链接。

    试试。加 -DBOOST_DATE_TIME_NO_LIB 和-DBOOST_REGEX_NO_LIB 声明到工程选项的c/C++/commandline后面,编译,成功!高兴!

    运行,ok!

    bjam编译参数请参考http://www.cppprog.com/2009/0112/48.html;转载如下:

    bjam参数
    --build-dir=<builddir> 编译的临时文件会放在builddir里(这样比较好管理,编译完就可以把它删除了)
    --stagedir=<stagedir> 存放编译后库文件的路径,默认是stage
    --build-type=complete 编译所有版本,不然只会编译一小部分版本(确切地说是相当于:variant=release, threading=multi;link=shared|static;runtime-link=shared)
    variant=debug|release 决定编译什么版本(Debug or Release?)
    link=static|shared 决定使用静态库还是动态库。
    threading=single|multi 决定使用单线程还是多线程库。
    runtime-link=static|shared 决定是静态还是动态链接C/C++标准库。
    --with-<library> 只编译指定的库,如输入--with-regex就只编译regex库了。
    --show-libraries 显示需要编译的库名称
  • 相关阅读:
    EBS R12.2 运行请求出错
    仿ORACLE的TRUNC函数
    EBS职责清单(Responsibility)
    Oracle 11G Client 客户端安装步骤
    UltraIso-写入硬盘映像
    EBS-WIP完工入库
    LeetCode 2 两数相加
    LeetCode 1.两数之和
    装饰器示例
    爬虫day1
  • 原文地址:https://www.cnblogs.com/lidabo/p/3782293.html
Copyright © 2011-2022 走看看