我正在使用包管理器 vcpkg
安装(静态)Boost
图书馆通过 vcpkg install boost:x64-windows-static
.
此外,我使用 CMake
作为我的构建系统,我正在通过 C:\vcpkg\scripts\buildsystems\vcpkg.cmake
至 CMake
通过 -DCMAKE_TOOLCHAIN_FILE
CMake
命令。
在我的 CMakeLists.txt
我强制静Boost
图书馆:
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS filesystem iostreams REQUIRED)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif ()
# ...
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
然而,
Visual Studio
仍然试图查看我的 Boost
的错误文件路径图书馆:Error 'C:/vcpkg/installed/x64-windows/lib/boost_filesystem-vc140-mt.lib', needed by 'MyProject.exe', missing and no known rule to make it
如果我安装动态
Boost
库,它会很好地构建,因为这是 Visual Studio
看起来。但是,我想在我的构建中使用静态库,以便所有 DLL
s 被“合并”到最后 EXE
.我怎样才能做到这一点?
最佳答案
我有同样的问题。
解决了
define set(Boost_INCLUDE_DIR "path")
在 find_package 强制之前。当您使用
cmake
与 vcpkg
, 查找 _VCPKG_INSTALLED_DIR
CmakeCache.txt
中的变量set(Boost_INCLUDE_DIR ${_VCPKG_INSTALLED_DIR}/x64-windows-static/include)
关于c++ - 在 vcpkg 和 CMake 中使用静态 Boost 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60132392/