You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下Boost 1.88 Cobalt模块LNK2019未解析外部符号问题

Boost Cobalt模块LNK2019未解析外部符号问题解决

背景与初始配置

  • Windows系统下通过bootstrap.bat和b2.exe cxxstd=20编译Boost 1.88,编译输出显示已构建cobalt模块并生成对应的*.lib文件。
  • 初始CMakeLists.txt配置如下:
find_package(Boost REQUIRED context system coroutine regex url PATHS "${BOOST_DIR}/bin/x64/lib/cmake")
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} Threads::Threads)
  • 注意到Boost_LIBRARIES的值为Boost::contextBoost::systemBoost::coroutineBoost::regexBoost::url,无空格分隔但仍能正常工作,对此存在疑问。
  • 根据b2.exe的输出提示,将G:\SoftwareDev\libs\boost\stage\lib添加到链接器库路径,在CMakeLists.txt中新增:link_directories("{BOOST_DIR}/stage/lib")。

出现的链接错误

编译项目时触发LNK2019未解析外部符号错误:

[...]\out\build\x64-Debug\main.cpp.obj : error LNK2019: unresolved external symbol "class std::pmr::memory_resource * __cdecl boost::cobalt::this_thread::set_default_resource(class std::pmr::memory_resource &)" (?set_default_resource@this_thread@cobalt@boost@@YAPEAVmemory_resource@pmr@std@@PEAV456@@Z) referenced in function "public: void __cdecl `int __cdecl main(int,char * * const)'::`2'::reset_res::operator()(class std::pmr::memory_resource &)" (??Rreset_res@?1??main@@YAHHQEAPEAD@Z@QEAAXPEAVmemory_resource@pmr@std@@@Z)
[...]\out\build\x64-Debug\main.cpp.obj : error LNK2019: unresolved external symbol "public: struct std::suspend_never __cdecl boost::cobalt::detail::main_promise::final_suspend(void)" (?final_suspend@main_promise@detail@cobalt@boost@@QEAA?AUsuspend_never@std@@XZ) referenced in function "class boost::cobalt::main __cdecl co_main$_ResumeCoro$1(int,char * * const)" (?co_main$_ResumeCoro$1@@YA?AVmain@cobalt@boost@@HQEAPEAD@Z)
[...]\out\build\x64-Debug\main.cpp.obj : error LNK2019: unresolved external symbol "public: static int __cdecl boost::cobalt::detail::main_promise::run_main(class boost::cobalt::main)" (?run_main@main_promise@detail@cobalt@boost@@SAHVmain@34@@Z) referenced in function main
[...]\out\build\x64-Debug\boost_beast_redirect.exe : fatal error LNK1120: 3 unresolved externals

已知同类问题的常规解决方案是用C++20编译Boost,但已按此要求编译仍出现错误。

解决方案尝试与最终结论

  • 仅配置原有非cobalt依赖项时,项目可正常构建:
find_package(Boost REQUIRED context system coroutine regex url PATHS "${BOOST_DIR}/bin/x64/lib/cmake")
  • 新增单独的cobalt依赖配置时,出现文件找不到错误(提示cannot open file 'libboost_url-vc143-mt-gd-x64-1_88.lib'):
find_package(Boost REQUIRED context system coroutine regex url PATHS "${BOOST_DIR}/bin/x64/lib/cmake")
find_package(Boost REQUIRED cobalt PATHS "${BOOST_DIR}/stage/lib/cmake")
  • 最终可行配置:将所有Boost依赖项(包括cobalt)合并到同一条find_package指令中,统一使用stage路径:
find_package(Boost REQUIRED context system coroutine regex url cobalt PATHS "${BOOST_DIR}/stage/lib/cmake")

内容的提问来源于stack exchange,提问作者user2366975

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 04:13:15