• [转]boost.asio 编译


    环境: VS2010,


    boost_1_46_1,解压缩后放在,D:\boost_1_46_1。


    1,编译。


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


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


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


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


    D:\boost_1_46_1>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_46_1加入到include directories中去,将D:\boost_1_46_1\stage\lib加入到Library
    Directories路径中去。



    2、测试。


    //  
    // timer.cpp  
    // ~~~~~~~~~  
    //  
    // Copyright (c)
    2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)  
    //  
    //
    Distributed under the Boost Software License, Version 1.0. (See accompanying  

    // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)  

    //  


    #include <iostream>  
    #include <boost/asio.hpp>  

    #include <boost/date_time/posix_time/posix_time.hpp>  


    int main()  
    {  
    boost::asio::io_service io;  


    boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));  

    t.wait();  


    std::cout << "Hello, world!\n";  


    return 0;  


    编译时提示建议添加一下编译参数来制定编译目标平台:


    1>  Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For
    example:
    1>  - add -D_WIN32_WINNT=0x0501 to the compiler command line;
    or
    1>  - add _WIN32_WINNT=0x0501 to your project's Preprocessor
    Definitions.
    1>  Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP
    target).


    编译pass~~



    补充一下:



    执行以上操作之前请执行:


    bootstrap.bat

     

     

    参考:


    http://blog.csdn.net/TADICAN/archive/2009/06/17/4273004.aspx

  • 相关阅读:
    C盘的可用空间忽大忽小
    安装软件时不能指定软件的安装目录
    MySQL安装排坑
    Butterfly主题目录生成不了问题
    apache+php安装配置的各种问题
    环境变量配置不成功
    http模块
    Node.js
    Spring Boot入门
    代码优化笔记
  • 原文地址:https://www.cnblogs.com/adylee/p/2064722.html
Copyright © 2020-2023  润新知