zoukankan      html  css  js  c++  java
  • boost throw_exception unresolved

    http://blog.csdn.net/is2120/archive/2011/05/02/6385304.aspx
    在用 VS2010 (vc2010)的cl.exe编译如下代码( boost asio 示例 )时,总是出现 throw_exception unresolved (link error)

    is2120@csdn@2011-5-2 23:35 copyright@is2120 ,转载请保留出处

    x.obj : error LNK2019: unresolved external symbol "void __cdecl boost::throw_exception(class std::exception const &)" (?throw_exception@boost@@YAXABVexception@std@@@Z) referenced in function "void __cdecl boost::asio::detail::do_throw_error(class boost::system::error_code const &,char const *)" (?do_throw_error@detail@asio@boost@@YAXABVerror_code@system@3@PBD@Z)

    初步查询资料得知是因定义了BOOST_EXCEPTION_DISABLE
    
    引起,在此宏被定义后需要用户自定义如下函数
    
    void throw_exception( std::exception const & e );

    这样定义一个函数,就有了第一个解决方案

    1. 可以定义一个函数throw_exception

    可是看上去挺别扭,继续搜,发现boost/config/compiler下有visualc.hpp,其中涉及BOOST_NO_EXCEPTIONS的部分如下

    #if !defined(_CPPUNWIND) && !defined(BOOST_NO_EXCEPTIONS)
    #  define BOOST_NO_EXCEPTIONS  
    #endif

    那么就有了2.

    2. 若要避免BOOST_EXCEPTION_DISABLE被定义,需要定义_CPPUNWIND,在文件中定义即可

    继续_CPPUNWIND ,msdn中说

       _CPPUNWIND          Defined for code compiled with Enable Exception
                           Handling (/GX).
    按照所说的使用选项/GX,结果又出现新情况
    cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
    cl : Command line warning D9036 : use 'EHsc' instead of 'GX'

    3. 或者在编译选项中使用/GX 或是 /EHsc,这样告诉编译器ENABLE EXCEPTION HANDLE,也可以。

    最后一种方法最自然最好哈;折腾了挺久,做个笔记。

    is2120@csdn@2011-5-2 23:35 copyright@is2120 ,转载请保留出处

    //#define _CPPUNWIND

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

    using namespace boost::asio;

    /*
    void boost::throw_exception( std::exception const & e )
    {

    }
    */

    int main(int argc, char* argv[])
    {
        // 所有asio类都需要io_service对象
        io_service iosev;
        ip::tcp::acceptor acceptor(iosev,
            ip::tcp::endpoint(ip::tcp::v4(), 1000));
        for(;;)
        {
            // socket对象
            ip::tcp::socket socket(iosev);
            // 等待直到客户端连接进来
            acceptor.accept(socket);
            // 显示连接进来的客户端
            std::cout << socket.remote_endpoint().address() << std::endl;
            // 向客户端发送hello world!
            boost::system::error_code ec;
            socket.write_some(buffer("hello world!"), ec);

            // 如果出错,打印出错信息
            if(ec)
            {
                std::cout <<
                    boost::system::system_error(ec).what() << std::endl;
                break;
            }
            // 与当前客户交互完成后循环继续等待下一客户连接
        }
        return 0;
    }

    is2120@csdn@2011-5-2 23:35 copyright@is2120 ,转载请保留出处
    http://blog.csdn.net/is2120/archive/2011/05/02/6385304.aspx

  • 相关阅读:
    Android 2.2 r1 API 中文文档系列(11) —— RadioButton
    Android API 中文 (15) —— GridView
    Android 中文 API (16) —— AnalogClock
    Android2.2 API 中文文档系列(7) —— ImageButton
    Android2.2 API 中文文档系列(6) —— ImageView
    Android 2.2 r1 API 中文文档系列(12) —— Button
    Android2.2 API 中文文档系列(8) —— QuickContactBadge
    [Android1.5]TextView跑马灯效果
    [Android1.5]ActivityManager: [1] Killed am start n
    Android API 中文(14) —— ViewStub
  • 原文地址:https://www.cnblogs.com/IS2120/p/6746049.html
Copyright © 2011-2022 走看看