LNK2019当包含asio标头时,使用cmake生成的解决方案 [英] LNK2019 when including asio headers, solution generated with cmake

查看:110
本文介绍了LNK2019当包含asio标头时,使用cmake生成的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cmake和boost库将一个大项目从gcc(Linux)移植到msvc(windows).

I am trying to port a big project from gcc (Linux) to msvc (windows), using cmake and boost libraries.

项目在gcc上编译并运行良好,但在msvc上返回以下错误:

The project compile and runs fine for gcc but on msvc it returns the following error:

Dyna.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 asio运行一个简单的项目,并且该项目奏效了,从技术上讲,它排除了boost的构建问题.

I tried running a simple project using boost asio and it worked, which teorethically excludes boost build problems.

CMakeLists.txt如下:(分离出感兴趣的部分)

The CMakeLists.txt is as follows: (separated the parts of interest)

    .
    .
    .
IF(WIN32)
          # Flags para garantir a compilação em windows
          SET(CMAKE_CXX_COMPILER icpl)
          SET(TPN_WIN32 "/D WIN32")
          SET(TPN_WIN32_LIB ws2_32.lib odbc32.lib odbccp32.lib)
          SET(CMAKE_EXE_LINKER_FLAGS /NODEFAULTLIB:LIBC;LIBCMT)

    ENDIF(WIN32)

    # Comando para se livrar de warning sobre o caminho da library pthread
    IF(COMMAND cmake_policy)
      cmake_policy(SET CMP0003 NEW)
    ENDIF(COMMAND cmake_policy)

    # Configuracao do TPN REALTIME
    # === inicio ===
    IF (REALTIME_YES)
      MESSAGE ("[TPN] REALTIME ENABLED")
      set(Boost_ADDITIONAL_VERSIONS "1.45.0")
      set(Boost_USE_MULTITHREAD ON)
      set(Boost_USE_STATIC_LIBS ON)
      FIND_PACKAGE( Boost "1.45.0" COMPONENTS system filesystem serialization program_options regex thread date_time REQUIRED)
      FIND_PACKAGE( Threads REQUIRED )

      set(HYDRO_CXX_FLAGS "-DREALTIME -DJOYSTICK")
      set(HYDRO_CXX_LFLAGS ${Boost_LIBRARIES})

      INCLUDE_DIRECTORIES(hydro)


       INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
        ENDIF (REALTIME_YES)
        # ===  final ===
        .
        .
        .

    TARGET_LINK_LIBRARIES(Dyna
      tpn
      preadyn
      ${WHERE_PREA3D}
      ${WHERE_WAMIT_IO}
      ${WHERE_WAMIT_CONVERTER}
      ${WHERE_TECLINE}
      ${HYDRO_CXX_LFLAGS}
      ${TPN_WIN32_LIB}
    )

预先感谢

推荐答案

尝试在cmake中将标志"/EHsc"添加到您的TPN_WIN32变量中. 看来MSVC不会引发异常,您需要在vcproj中启用它.

Try to add the flag "/EHsc" into your TPN_WIN32 variable in cmake. It seems that MSVC is not throwing exceptions and you need to enable it in your vcproj.

这篇关于LNK2019当包含asio标头时,使用cmake生成的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆