windows vcpkg boost 开发环境

前置条件

  1. install vcpkg
  2. vcpkg install boost-system:x64-windows boost-filesystem:x64-windows

cmake boost 配置

if (WIN32)  
# 查找 Boost 库  
find_package(Boost COMPONENTS filesystem system REQUIRED)  
if (Boost_FOUND)  
include_directories(${Boost_INCLUDE_DIRS})  
link_directories(${Boost_LIBRARY_DIRS})  
endif ()  
endif (WIN32)

编译报错

====================[ Build | radar_data_local_storage | Release-Visual Studio ]====
......
CMake Error at C:/Program Files/JetBrains/CLion 2023.1.4/bin/cmake/win/x64/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Boost (missing: Boost_INCLUDE_DIR filesystem system)
Call Stack (most recent call first):
  C:/Program Files/JetBrains/CLion 2023.1.4/bin/cmake/win/x64/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/JetBrains/CLion 2023.1.4/bin/cmake/win/x64/share/cmake-3.25/Modules/FindBoost.cmake:2377 (find_package_handle_standard_args)
  C:/Users/luyang/.clion-vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake:855 (_find_package)
  TestDemo/CMakeLists.txt:8 (find_package)


CMake Configure step failed.  Build files cannot be regenerated correctly.
-- Configuring incomplete, errors occurred!
See also "C:/Users/luyang/Documents/TestDemo/cmake-build-release-visual-studio/CMakeFiles/CMakeOutput.log".

增加 :set(Boost_INCLUDE_DIR ${_VCPKG_INSTALLED_DIR}/x64-windows/include)

if (WIN32)  
# 查找 Boost 库  
set(Boost_INCLUDE_DIR ${_VCPKG_INSTALLED_DIR}/x64-windows/include)  
find_package(Boost COMPONENTS filesystem system REQUIRED)  
if (Boost_FOUND)  
include_directories(${Boost_INCLUDE_DIRS})  
link_directories(${Boost_LIBRARY_DIRS})  
endif ()  
endif (WIN32)

链接 boost-system boost-filesystem

if (WIN32)
target_link_libraries(radar_data_local_storage Boost::filesystem Boost::system)
endif(WIN32)