如何用vcpkg安装第三方库?能否不依赖CMake实现?
使用VCPKG配置concurrencpp的问题及求助
使用VCPKG的操作流程
我按照concurrencpp官方文档的构建安装步骤操作,已先执行命令:
vcpkg integrate install
项目根目录下的vcpkg.json内容如下:
{ "name": "vcpkg-test", "version-string": "1.0.0", "dependencies": ["concurrencpp"] }
在Visual Studio命令行中执行以下命令:
vcpkg x-update-baseline --add-initial-baseline vcpkg install --triplet x64-windows
命令执行输出结果:
D:\project_CPP\C++_study\vcpkg_project\cpp20-test>vcpkg install --triplet x64-windows Fetching registry information from https://github.com/microsoft/vcpkg (HEAD)... Detecting compiler hash for triplet x64-windows... The following packages will be built and installed: concurrencpp[core]:x64-windows -> 0.1.7 -- C:\Users\michaelyin\AppData\Local\vcpkg\registries\git-trees\5eb63527141d7d261b6e99945f81bf43e293cc8b * vcpkg-cmake[core]:x64-windows -> 2023-05-04 -- C:\Users\michaelyin\AppData\Local\vcpkg\registries\git-trees\88a7058fc7fa73a9c4c99cfcae9d79e2abf87a5a * vcpkg-cmake-config[core]:x64-windows -> 2022-02-06#1 -- C:\Users\michaelyin\AppData\Local\vcpkg\registries\git-trees\8d54cc4f487d51b655abec5f9c9c3f86ca83311f Additional packages (*) will be modified to complete this operation. Restored 3 package(s) from C:\Users\michaelyin\AppData\Local\vcpkg\archives in 1.2 s. Use --debug to see more details. Installing 1/3 vcpkg-cmake-config:x64-windows... Elapsed time to handle vcpkg-cmake-config:x64-windows: 43.9 ms Installing 2/3 vcpkg-cmake:x64-windows... Elapsed time to handle vcpkg-cmake:x64-windows: 51.1 ms Installing 3/3 concurrencpp:x64-windows... Elapsed time to handle concurrencpp:x64-windows: 214 ms Total install time: 1.5 s concurrencpp provides CMake targets: # this is heuristically generated, and may not be correct find_package(concurrencpp CONFIG REQUIRED) target_link_libraries(main PRIVATE concurrencpp::concurrencpp)
测试代码(与官方示例一致):
#include "concurrencpp/concurrencpp.h" #include <iostream> int main() { return 0; }
原本以为vcpkg会自动处理头文件路径和链接依赖,但实际出现以下错误:
Error :Error (active) E1696 cannot open source file "concurrencpp/concurrencpp.h" cpp20new D:\project_CPP\C++_study\cpp20new\cpp20new\cpp20new.cpp 4
仅使用CMake的可行方案(供参考)
不依赖vcpkg,纯CMake方式可以正常运行,步骤如下:
- 在Visual Studio中创建CMake项目
- 在项目根目录执行以下命令克隆并构建concurrencpp:
git clone https://github.com/David-Haim/concurrencpp.git cd concurrencpp cmake -S . -B build/lib
编辑项目的CMakeLists.txt文件:
project ("CMakeProject1") # Add source to this project's executable. add_executable (CMakeProject1 "CMakeProject1.cpp" "CMakeProject1.h") include(concurrencpp/cmake/coroutineOptions.cmake) include(FetchContent) FetchContent_Declare(concurrencpp SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/concurrencpp") FetchContent_MakeAvailable(concurrencpp) target_compile_features(CMakeProject1 PRIVATE cxx_std_20) target_link_libraries(CMakeProject1 PRIVATE concurrencpp::concurrencpp)
核心问题
如何通过vcpkg管理concurrencpp库,且不依赖CMake实现?
内容的提问来源于stack exchange,提问作者Michael
相关产品推荐
相关产品推荐

