没有找到带有 vcpkg 的 <package>.cmake

Didnt find <package>.cmake with vcpkg

提问人:KosmoFromTheRedStars 提问时间:11/14/2023 最后编辑:KosmoFromTheRedStars 更新时间:11/14/2023 访问量:34

问:

Could not find a package configuration file provided by "Xlnt" with any of
the following names:

    XlntConfig.cmake
    xlnt-config.cmake

Add the installation prefix of "Xlnt" to CMAKE_PREFIX_PATH or set
"Xlnt_DIR" to a directory containing one of the above files.  If "Xlnt"
provides a separate development package or SDK, be sure it has been
installed.

CMakeLists.txt

cmake_minimum_required(VERSION 3.25.2)
SET(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(untitled)
set(CMAKE_CXX_STANDARD 17)
add_executable(untitled main.cpp)
find_package(Xlnt CONFIG REQUIRED)
find_package(duckx CONFIG REQUIRED)
target_link_libraries(untitled PRIVATE xlnt::xlnt)
target_link_libraries(untitled PRIVATE duckx::duckx)

vcpkg.json

{
"name" : "untitled",
"dependencies" : [ {
"name" : "duckx",
"version>=" : "1.2.2#1"
}, {
"name" : "xlnt",
"version>=" : "1.5.0#4"
} ]
}

IDE:Clion,使用 vcpkg。

P.S. 初学者

尝试使用另一个(来自 clion,可能他们的配置比我的更好)vcpkg。 尝试添加

include_directories("C:\\vcpkg\\packages\\xlnt_x64-windows")
link_directories("C:\\vcpkg\\packages\\xlnt_x64-windows")

没有任何变化。 当我添加时

include("C:/vcpkg/scripts/buildsystems/vcpkg.cmake")

我采取:

"C:\Program Files\JetBrains\CLion 2023.1.5\bin\cmake\win\x64\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2023.1.5/bin/ninja/win/x64/ninja.exe" -G Ninja -S C:\Users\Kosmo\CLionProjects\untitled -B C:\Users\Kosmo\CLionProjects\untitled\cmake-build-debug -- Running vcpkg install error: C:\Users\Kosmo\CLionProjects\untitled\vcpkg.json was rejected because it uses "version>=" and does not have a "builtin-baseline". This can be fixed by removing the uses of "version>=" or adding a "builtin-baseline". See 'vcpkg help versioning for more information. -- Running vcpkg install - failed CMake Error at C:/vcpkg/scripts/buildsystems/vcpkg.cmake:899 (message):   vcpkg install failed.  See logs for more information:   C:\Users\Kosmo\CLionProjects\untitled\cmake-build-debug\vcpkg-manifest-install.log Call Stack (most recent call first):   C:/Program Files/JetBrains/CLion 2023.1.5/bin/cmake/win/x64/share/cmake-3.25/Modules/CMakeDetermineSystem.cmake:124 (include)   CMakeLists.txt:3 (project) CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage -- Configuring incomplete, errors occurred! [Failed to reload]

这个问题没有解决。删除了包含,删除了构建目录。

cmake vcpkg

评论

0赞 Alexander Neumann 11/14/2023
我认为你得到的最后一个错误很容易解决。您需要在清单中定义基线。

答:

0赞 NelDav 11/14/2023 #1

我不太了解 vcpkg,所以不确定我是否可以提供帮助。 正如您在错误消息中看到的那样,对于您要查找的每个包,cmake 都会搜索一个名为 或 的文件。 在您的情况下,它找不到它们。 这可能是因为 cmake 在错误的位置搜索。<PackageName>Config.cmake<PackageName>-config.cmake

由于您使用配置模式,因此 cmake 会在位于变量中存储的路径中的某些目录中搜索它们。 更详细的描述可以在这里找到:https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedureCMAKE_PREFIX_PATH

但是,您不希望手动将这些文件移动到那里。 我检查了 vcpkg 文档,它指出,您应该在项目目录中创建一个文件:CMakePresets.json

{
  "version": 3,
  "configurePresets": [
    {
      "name": "default",
      "binaryDir": "${sourceDir}/build",
      "cacheVariables": {
        "CMAKE_TOOLCHAIN_FILE": "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
      }
    }
  ]
}

借助此文件,vcpkg 将生成一个文件,从而可以找到包。CMakeToolchain.cmake

来源:https://learn.microsoft.com/en-us/vcpkg/get_started/get-started?pivots=shell-c

评论

0赞 KosmoFromTheRedStars 11/14/2023
谢谢。我只需要MSVC。