zoukankan      html  css  js  c++  java
  • windows下用vs2008和boost结合编译程序

     
    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://co63oc.blog.51cto.com/904636/504469

    windows下用vs2008和boost结合编译程序
    vc6.0和boost结合出现很多错误

    使用asio子库中一个http server的示例程序,代码在libsasioexamplehttpserver目录下。

    1. 下载boost源文件
    http://sourceforge.net/projects/boost/files/boost/1.46.0/
    2. 下载boost编译管理工具bjam,它调用系统安装的编译器编译源程序
    http://sourceforge.net/projects/boost/files/boost-jam/3.1.18/boost-jam-3.1.18-1-ntx86.zip
    3. 假设boost的压缩文件解压到F:oost,boost-jam解压到F:oost-jam
    打开命令提示符,
    F:
    cd F:oost
    F:oost-jamjam.exe install
    这样会编译并安装boost库到C:oost
    4. vs2008中打开菜单Tools->Options->Projects and Solutions->VC++ Directories
    在Include files中增加C:Boostinclude
    在Library files中增加C:Boostlib

    5. 新建vs 2008 MFC Application项目mfc2008_boost1,
    使用Release配置
    Project->Project Properties...->Configuration Properties->C/C++->Precompiled Headers中设置Create/Use Precompiled Header为Not Using Precompiled Headers,即不使用预编译头,否则编译boost示例程序出现预编译错误。
    6. 复制boost源码中libsasioexamplehttpserver下所有hpp, cpp文件到项目代码目录
    7. 编辑mfc2008_boost1Dlg.cpp。
    这是增加的代码,从win_main.cpp中复制。
    #include "stdafx.h"

    #include <iostream>
    #include <string>
    #include <boost/asio.hpp>
    #include <boost/bind.hpp>
    #include <boost/function.hpp>
    #include "server.hpp"

    #include "mfc2008_boost1.h"
    #include "mfc2008_boost1Dlg.h"

    Cmfc2008_boost1Dlg类中增加一线程函数:
    unsigned int Cmfc2008_boost1Dlg::Thread1(LPVOID param)
    要增加及修改代码:
    boost::function0<void> console_ctrl_function;

    BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
    {
        switch (ctrl_type)
        {
        case CTRL_C_EVENT:
        case CTRL_BREAK_EVENT:
        case CTRL_CLOSE_EVENT:
        case CTRL_SHUTDOWN_EVENT:
            console_ctrl_function();
            return TRUE;
        default:
            return FALSE;
        }
    }

    unsigned int Cmfc2008_boost1Dlg::Thread1(LPVOID param)
    {
        try
        {
            // Initialise server.
            http::server::server s("localhost", "88", "F:\");  //本地88端口监听,访问根目录为F:

            // Set console control handler to allow server to be stopped.
            console_ctrl_function = boost::bind(&http::server::server::stop, &s);
            SetConsoleCtrlHandler(console_ctrl_handler, TRUE);

            // Run the server until stopped.
            s.run();
        }
        catch (std::exception& e)
        {
            std::cerr << "exception: " << e.what() << " ";
        }

        return 0;
    }
    8. OnInitDIalog中增加线程创建代码:
    AfxBeginThread(Thread1, NULL);
    9. 删除win_main.cpp
    10. 按F7编译项目。Ctrl+F5运行
    11. 浏览器打开http://localhost:88/,出现404错误提示,这说明服务已经启动。输入 http://localhost:88/+"F: 下文件名" 可访问。

    编译boost需要很长时间,有网站制作了编译好的boost库,www.boostpro.com
    下载安装程序,按提示选择编译环境和需要的库安装。

  • 相关阅读:
    mysql 自定义排序
    arcgis 好人
    eclipse启动tomcat,提示三个端口均被占用
    oracle 查看表空间创建日期
    navacat 链接oracle oci invalid handle
    java +mysql 递归排序/* START WITH aa.parentid IN ( 10000, 20000, 30000, 40000, 50000, 60000, 70000 ) connect BY prior aa.id = aa.parentid ORDER siblings BY aa.id ASC*/ to
    Double 转 BigDecimal
    mysql 死锁 Waiting for stored function metadata lock
    Graphtree--zabbix增强功能(一屏展示所有内容)
    zabbix 分布式监控(proxy)源码安装
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/4445123.html
Copyright © 2011-2022 走看看