I installed VSCode
, MSYS2 UCRT64
— GCC
and cmake
in it. I specified the compiler with the following code:
CMakelists.txt:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_C_COMPILER "D:/msys64/ucrt64/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "D:/msys64/ucrt64/bin/g++.exe")
project(MyCppProject)
tasks.json:
"label": "cmake-configure",
"type": "shell",
"command": "cmake",
"args": [
"-S", "${workspaceFolder}",
"-B", "${workspaceFolder}/build",
"-DCMAKE_C_COMPILER=D:/msys64/ucrt64/bin/gcc.exe",
"-DCMAKE_CXX_COMPILER=D:/msys64/ucrt64/bin/g++.exe"
],
If I use Ctrl+Shift+P to call the CMake: Configure
and CMake: Build
, it will auto detect the vs cl.exe
compiler rather than g++
.
Only when I manually execute cmake -S . -B build
and cmake --build build
in the cppdbg
terminal, it could compile with g++.
Although I'm glad with this manual command calling, in some other PC, I can't even find this cppdbg
terminal — there is only the powershell. How can I open it on the other PC?
I find the trick, the default `build` schema is there:
C:\Users\username\AppData\Roaming\Code\User\tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "cl.exe",
"args": [
"/EHsc",
"/Zi",
"${file}",
"/Fe:${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$msCompile"]
}
]
}