【问题标题】:Cmake cant find the required Packages for meCmake 无法为我找到所需的软件包
【发布时间】:2021-08-11 11:38:13
【问题描述】:

所以My Workspace Screenshot 尝试了一段时间后,即使我按照 vcpkg 中所示的方式完成了所有操作,我也无法获取 Cmake 来找到所需的包

cmake_minimum_required(VERSION 3.0.0)
project(TEst VERSION 0.1.0)

include(CTest)
enable_testing()
set(CMAKE_TOOLCHAIN_FILE "N:/Vc-PKG/vcpkg/scripts/buildsystems/vcpkg.cmake")
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(TEst PRIVATE glfw)
add_executable(TEst main.cpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

我的 Vcpkg 安装目录是N:\Vc-PKG\vcpkg 我还在 vscode 中添加了这些行

    "C_Cpp.default.includePath": [
        "N:/Vc-PKG/vcpkg/installed/x64-windows/include",
        "N:/Vc-PKG/vcpkg/installed/x86-windows/include",
    ],
    "c-cpp-flylint.cppcheck.includePaths": [
        "N:\\Vc-PKG\\vcpkg\\installed\\x64-windows\\include",
        "N:\\Vc-PKG\\vcpkg\\installed\\x86-windows\\include",
    ],
    "cmake.generator": "MinGW Makefiles",

我得到的输出如下是

[main] Configuring folder: Junks 
[proc] Executing command: N:\MSYS64\mingw64\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=N:\MSYS64\mingw64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=N:\MSYS64\mingw64\bin\x86_64-w64-mingw32-g++.exe "-Hl:/Programming Projects/Vs Code/Junks" "-Bl:/Programming Projects/Vs Code/Junks/build" -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error at CMakeLists.txt:7 (find_package):
[cmake]   Could not find a package configuration file provided by "glfw3" with any of
[cmake]   the following names:
[cmake] 
[cmake]     glfw3Config.cmake
[cmake]     glfw3-config.cmake
[cmake] 
[cmake]   Add the installation prefix of "glfw3" to CMAKE_PREFIX_PATH or set
[cmake]   "glfw3_DIR" to a directory containing one of the above files.  If "glfw3"
[cmake]   provides a separate development package or SDK, be sure it has been
[cmake]   installed.
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "L:/Programming Projects/Vs Code/Junks/build/CMakeFiles/CMakeOutput.log".
[cmake] 

如果我犯了错误,请提供任何帮助,抱歉,这是我第一次发布问题。

【问题讨论】:

  • 你已经vcpkg integrate install了吗?
  • 是的,我已经进行了 vcpkg 集成安装,它可以在我的家用电脑上很好地使用 Visual Studio 在我的笔记本电脑上购买 Vscode 我无法让它开始工作
  • 您是否在某处设置了 vcpkg_DIR(在 envcmakelists.txt 中)?

标签: c++ cmake vcpkg


【解决方案1】:

您不能在调用project() 后设置CMAKE_TOOLCHAIN_FILE。这是首先负责加载工具链文件的命令。在调用 project() 之前将其移动到或更好:在命令行或预设中设置它。

此外,除非您实际使用的是 CMake 3.0.0,否则不应将其设置为最小值。 CMake 不向前兼容,所以如果没有在最低版本上实际测试它,你就无法知道它是否能在那么远的时候工作。

【讨论】:

  • @M.F.R.Siam - 很高兴为您提供帮助,欢迎来到 StackOverflow!如果此答案解决了您的问题,请考虑接受(复选标记)和/或投票(向上箭头)。
猜你喜欢
  • 2018-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-05
  • 2019-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多