C++ cmake找不到与vcpkg一起安装的库

C++ cmake找不到与vcpkg一起安装的库,c++,boost,cmake,xerces,vcpkg,C++,Boost,Cmake,Xerces,Vcpkg,我想在Windows中的CMake项目中使用vcpkg,因为我需要boost和xerces这两个包管理器处理 我有以下CMakeLists.txt: cmake_minimum_required (VERSION 3.12.0) project (myproj) set (CMAKE_PREFIX_PATH ${XERCES_ROOT}) set (Boost_USE_STATIC_LIBS ON) set (Boost_USE_MULTITHREADED ON) unset (Boost_

我想在Windows中的CMake项目中使用
vcpkg
,因为我需要
boost
xerces
这两个包管理器处理

我有以下
CMakeLists.txt

cmake_minimum_required (VERSION 3.12.0)

project (myproj)

set (CMAKE_PREFIX_PATH ${XERCES_ROOT})
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED ON)
unset (Boost_INCLUDE_DIR CACHE)
unset (Boost_LIBRARY_DIRS CACHE)

# set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules)
find_package (Boost COMPONENTS filesystem regex REQUIRED)
find_package (XercesC CONFIG REQUIRED)

set (CMAKE_INCLUDE_CURRENT_DIR ON)
message (STATUS "binary dir is ${CMAKE_BINARY_DIR}")
include_directories (${CMAKE_BINARY_DIR}/${PROJECT_NAME}/)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories (${Boost_INCLUDE_DIRS})
include_directories (${XercesC_INCLUDE_DIRS})

set (PROJECT_SRC
  code.cpp
  )

add_library (${PROJECT_NAME} SHARED ${PROJECT_SRC})
add_dependencies (${PROJECT_NAME} UPDATE_RESOURCES)
target_link_libraries (${PROJECT_NAME} ${Boost_LIBRARIES} XercesC::XercesC)
Boost
xerces-c
vcpkg
一起安装。因为我使用的是Visual Studio代码,所以我在settings.json中设置vcpkg变量:

  "cmake.configureSettings": {
    "CMAKE_TOOLCHAIN_FILE" : "some/path/vcpkg/scripts/buildsystems/vcpkg.cmake",
    "VCPKG_TARGET_TRIPLET": "x64-windows"
  }
当我运行che CMake时,我得到以下错误:

[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:2132 (message):
[cmake]   Unable to find the requested Boost libraries.
[cmake] 
[cmake]   Unable to find the Boost header files.  Please set BOOST_ROOT to the root
[cmake]   directory containing Boost or BOOST_INCLUDEDIR to the directory containing
[cmake]   Boost's headers.
[cmake] Call Stack (most recent call first):
[cmake]   D:/projects/vcpkg/scripts/buildsystems/vcpkg.cmake:233 (_find_package)
[cmake]   src/myroject/CMakeLists.txt:24 (find_package)
[cmake] 
[cmake] 
[cmake] CMake Error at D:/Projects/vcpkg/installed/x64-windows/share/xercesc/vcpkg-cmake-wrapper.cmake:1 (_find_package):
[cmake]   Could not find a package configuration file provided by "XercesC" with any
[cmake]   of the following names:
[cmake] 
[cmake]     XercesCConfig.cmake
[cmake]     xercesc-config.cmake
[cmake] 
[cmake]   Add the installation prefix of "XercesC" to CMAKE_PREFIX_PATH or set
[cmake]   "XercesC_DIR" to a directory containing one of the above files.  If
[cmake]   "XercesC" provides a separate development package or SDK, be sure it has
[cmake]   been installed.
[cmake] Call Stack (most recent call first):
[cmake]   D:/Projects/vcpkg/scripts/buildsystems/vcpkg.cmake:189 (include)
[cmake]   src/ZLA/CMakeLists.txt:25 (find_package)
[cmake] 
[cmake] 
[cmake] Configuring incomplete, errors occurred!
[cmake] See also "D:/Projects/zla/build/vscode/CMakeFiles/CMakeOutput.log".
[cms-driver] Error during CMake configure: [cmake-server] Configuration failed.
目前我已经用vcpkg命令安装了
xerces
,而boost目前还没有安装,但我希望在执行cmake命令期间,
vcpkg
将下载并构建所需的构建包

我还尝试了命令行:

 cmake -DCMAKE_TOOLCHAIN_FILE=D:/Projects/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ../
但结果是一样的

我做错了什么?如何成功使用vcpkg

boost目前尚未安装,但我希望在执行cmake命令期间,vcpkg将下载并构建所需的构建包

据我所知,情况并非如此。对于计划使用的三元组(即
x64 windows
),您需要事先安装使用
vcpkg
的软件包。然后,您需要确保在运行CMake时使用了正确的三元组(检查
CMakeCache.txt
中的
VCPKG\u TARGET\u三元组
变量)。如果不正确,您可以更改它并使用CMake重新配置

此外,根据您得到的错误输出,似乎没有使用
vcpkg
正确安装
xerces
。您可以通过运行以下命令来检查随
vcpkg
安装的内容:


vcpgg列表——triplet x64 windows

我也遇到了同样的问题,只是通过以下方法解决了它:

set(CURL_DIR "C:/Libs/vcpkg/installed/x64-windows/share/curl")

我在C:/Libs下安装了vcpkg

  • 您需要事先安装这些软件包(使用vcpkg安装)
  • (然后可以将工具链指定为CMake选项:

    但是,如果已经指定了工具链(例如交叉编译时),这将不起作用。)

  • 而是“包含”它以避免此问题:
  • 在find_package()之前,将此行添加到项目CMakeLists.txt中:


    我已经执行了命令,xerces似乎已安装:
    xerces-c:x64 windows 3.2.2-8 xerces-c++是一个XML解析器,用于解析,生成…
    。在
    cmakcache.txt
    中,我得到了正确的三元组:
    vcpgg\u TARGET\u三元组:STRING=x64 windows
    @Jepessen好的,boost怎么样?我现在用
    vcpgg安装boost:x64 windows
    安装它们。这需要一段时间。但我认为问题在于xerces,因为它对所有库都是一样的。对于XercesC,从
    find_包调用中删除
    CONFIG
    。如果使用
    vcpkg
    安装了库,则CMake应该能够找到该库。是否删除CMake缓存中的所有XercesC变量并重新配置?
    list(APPEND CMAKE_PREFIX_PATH "C:/Libs/vcpkg/packages/curl_x64-windows/share/curl/")
    
    -DCMAKE_TOOLCHAIN_FILE=C:\path\to\vcpkg\scripts\buildsystems\vcpkg.cmake
    
    include(/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake)