【发布时间】: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