如何使用 CMake 在 Windows 上正确链接 Boost 库?

你好 我正在努力使用 CMake 构建系统从 Windows 上的 Boost.Asio 模块构建示例。我想静态链接 boost 库。我用 b2 --with-system --with-thread --with-date_time --with-regex --with-serialization stage 构建了库(默认输出目录是 bin.v2)。我的 CMakeLists.txt 看起来像

add_executable(network_communicator  main.cpp)
set(BOOST_ROOT "C:\\boost_1_76_0\\")
set(BOOST_libraRYDIR "C:\\boost_1_76_0\\bin.v2\\libs")
SET(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS thread REQUIRED)
target_include_directories(network_communicator PRIVATE external)
target_compile_definitions(network_communicator PRIVATE _WIN32_WINNT=0x0601)
target_link_directories(network_communicator PRIVATE "C:\\boost_1_76_0\\bin.v2\\libs")

然而,在构建项目时,编译器在链接阶段产生错误

链接:致命错误 LNK1104:无法打开文件“libboost_date_time-vc142-mt-gd-x64-1_76.lib”

如何正确、巧妙地构建和链接 Boost 库?

henryjiangyun 回答:如何使用 CMake 在 Windows 上正确链接 Boost 库?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/33007.html

大家都在问