gpt4 book ai didi

c++ - LNK2019 当包含 asio header 时,使用 cmake 生成的解决方案

转载 作者:可可西里 更新时间:2023-11-01 16:26:03 26 4
gpt4 key购买 nike

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

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

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 构建问题。

CMakeLists.txt如下:(将感兴趣的部分分开)

    .
.
.
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}
)

提前致谢

最佳答案

尝试将标志“/EHsc”添加到 cmake 中的 TPN_WIN32 变量中。MSVC 似乎没有抛出异常,您需要在 vcproj 中启用它。

关于c++ - LNK2019 当包含 asio header 时,使用 cmake 生成的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6832666/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com