环境:win10 vscode1.95.3 clang15.0.4
问题:最近用vscode+cmake+clang在windows上编译c++项目,用mingw32不报错,用clang报错,错误如下,
MSBUILD : error MSB1009: 项目文件不存在。
原因:与其他生成器(如Makefiles或Ninja)不同,CMake不为Visual Studio解决方案生成all目标,而是生成ALL_BUILD目标。
解决:在CMakePresets.json新增buildPresets,name设为ALL_BUILD
CMakePresets.json
{
"version": 8,
"configurePresets": [
{
"name": "clang",
"displayName": "Clang 15.0.4 x86_64-w64-windows-gnu",
"description": "Using compilers: C = D:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\openharmony\\native\\llvm\\bin\\clang.exe, CXX = D:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\openharmony\\native\\llvm\\bin\\clang++.exe",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_C_COMPILER": "D:/Program Files/Huawei/DevEco Studio/sdk/default/openharmony/native/llvm/bin/clang.exe",
"CMAKE_CXX_COMPILER": "D:/Program Files/Huawei/DevEco Studio/sdk/default/openharmony/native/llvm/bin/clang++.exe",
"CMAKE_BUILD_TYPE": "Debug"
},
"generator": "Visual Studio 15 2017"
}
],
"buildPresets": [
{
"name": "ALL_BUILD",
"description": "",
"displayName": "",
"configurePreset": "clang"
}
]
}