我遇到了类似的问题。使用 runtime-debugging=on 或 off 构建将构建没有 g 标记的 .lib 文件。
b2 -a -j16 toolset=clang-win cxxflags="-D_CRT_SECURE_NO_WARNINGS -D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING" architecture=x86 address-model=64 runtime-link=static runtime-debugging=on --build-type=complete --layout=tagged variant=debug,release --without-mpi --without-python stage --stagedir=clangw10
会产生像 libboost_thread-mt-sd-x64.lib 这样的文件,并且链接它会破坏链接过程,例如:
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\Llvm\bin\lld-link.exe CMakeFiles\test.dir\cmake_pch.cxx.obj CMakeFiles\test.dir\resources\win.rc.res CMakeFiles\test.dir\main.cpp.obj /out:test.exe /implib:test.lib /pdb:test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:windows E:\SDKs\boost_1_72_0\stage\lib\libboost_thread-mt-sd-x64.lib E:\SDKs\boost_1_72_0\stage\lib\libboost_chrono-mt-sd-x64.lib E:\SDKs\boost_1_72_0\stage\lib\libboost_date_time-mt-sd-x64.lib E:\SDKs\boost_1_72_0\stage\lib\libboost_atomic-mt-sd-x64.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\test.dir/intermediate.manifest CMakeFiles\test.dir/manifest.res" failed (exit code 1) with the following output:
E:\Workspace\test\build\x64-Debug\lld-link : error : could not open 'boost_thread-clangw10-mt-gd-x64-1_72.lib': no such file or directory
E:\Workspace\test\build\x64-Debug\lld-link : error : could not open 'libboost_date_time-clangw10-mt-gd-x64-1_72.lib': no such file or directory
E:\Workspace\test\build\x64-Debug\lld-link : error : could not open 'libboost_chrono-clangw10-mt-gd-x64-1_72.lib': no such file or directory
看起来这些库都依赖于运行时调试,但如果没有 b2 能够生成这些库,我几乎就被困在这上面了。
更新
通过在 .lib 的文件名中添加“g”并使用 --layout=versioned
构建提升,我能够成功地将我的程序与 cmake 链接
为了链接正确的文件,我必须在 CMakeLists.txt
中添加
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")