【问题标题】:How to configure VS Code's CMake Tools Extension for GCC and MSYS Makefiles on Windows?如何在 Windows 上为 GCC 和 MSYS Makefile 配置 VS Code 的 CMake 工具扩展?
【发布时间】:2023-01-02 03:53:59
【问题描述】:

这个问题是关于CMake 工具扩展为VS代码.操作系统为Windows 10。

该扩展正确地找到了 GCC,我可以通过查看 %LocalAppData%/CMakeTools/cmake-tools-kits.json 来验证这一点。

{
  "name": "GCC 10.3.0 x86_64-w64-mingw32",
  "compilers": {
    "C": "C:\\msys64\\mingw64\\bin\\x86_64-w64-mingw32-gcc.exe",
    "CXX": "C:\\msys64\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe"
  }
}

我尝试通过相应的 VS Code 命令进行配置,但出现错误:

[rollbar] Unhandled exception: Unhandled Promise rejection: configure Error: No usable generator found. {}

然后我将相应的设置添加到我的本地设置.vscode/settings.json

{ "cmake.generator": "MSYS Makefiles" }

我得到以下输出:

[proc] Executing command: "C:/Program Files/CMake/bin/cmake.exe" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\x86_64-w64-mingw32-g++.exe -H<path to project root> -B<path to build directory> -G "MSYS Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error: CMake was unable to find a build program corresponding to "MSYS Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
[cmake] CMake Error: CMake was unable to find a build program corresponding to "MSYS Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
[cmake] CMake Error: CMAKE_AR was not found, please set to archive program. 
[cmake] -- Configuring incomplete, errors occurred!

所以我扩展了我的本地设置。

{
  "cmake.generator": "MSYS Makefiles",
  "cmake.environment": {
    "CMAKE_AR": "C:/msys64/usr/bin/ar.exe",
    "CMAKE_MAKE_PROGRAM": "C:/msys64/usr/bin/make.exe"
  }
}

获得与之前相同的输出。我还尝试在 CMakeLists.txt 中将这些变量设置为系统环境变量。

这样做的正确方法是什么?

【问题讨论】:

  • 变量CMAKE_MAKE_PROGRAM是一个变量, 不是环境一。 (该变量未列在environment variables affecting on CMake 中)。因此,要设置此变量,您需要使用“cmake.configureSettings”而不是“cmake.environment”。
  • @Tsyvarev 就是这样。谢谢你。我对环境和 CMake 变量感到困惑。但是,您为什么不将其发布为答案?

标签: visual-studio-code cmake vscode-settings msys2


【解决方案1】:

我知道这是一个古老的要求,但我最近一直遇到这个问题。

我发现的技巧(在 Windows 上使用当前版本的 MSYS2)是安装 mingw64 的 cmake 版本。

使用命令:

pacman -S mingw-w64-x86_64-cmake

注意:这假定 pacman 已在您的路径中定义,否则您需要在 pacman 前加上路径前缀。

然后安装忍者:

pacman -S ninja

您不需要在 VSCode 设置中定义配置,它应该可以正常工作。

【讨论】:

    猜你喜欢
    • 2022-06-21
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 2022-01-25
    • 1970-01-01
    • 2021-05-14
    • 1970-01-01
    • 2022-07-10
    相关资源
    最近更新 更多