Use VScode configuration c / c ++ development environment on Mac
Cry Liao, Typora which is best not to insert the expression, or saved will flash back
- First, you need to have a vscode
Inside the extended download c / c ++
first step
⬆ + com + p Open Command mode: select c / c ++: Configuration Editor (edit configuration)
and then automatically generated .vscode directory, open c_cpp_properties.json. Use my brother's file:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Library/Developer/CommandLineTools/usr/include/c++/v1",
"/usr/local/include",
"/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include",
"/Library/Developer/CommandLineTools/usr/include"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks",
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
Will be used inside the library to includePath
Step two:
[⇧⌘P] Open the command mode, select [Tasks: Configure Task] command, select a template for MSBuild, after the carriage return will automatically generate a file in the .vscode tasks.json directory, given below my file:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build c++",
"type": "shell",
"command": "g++",
"args": [
"${file}",
"-std=c++17",
"-g",
"-Wall",
"-lm",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.out"
],
"group": "build",
"presentation": {
"reveal": "silent",
"panel": "shared",
"echo": true,
"focus": false,
"showReuseMessage": true,
"clear": false
},
"problemMatcher": "$gcc"
},
{
"label": "run c++",
"type": "shell",
"dependsOn": "build c++",
"command": "${fileDirname}/${fileBasenameNoExtension}.out",
"presentation": {
"focus": true
},
"group": "test"
}
]
}
- We do not know a lot of parameters, first copy it
The file is actually a command-line build tool.
When you run the command in a terminal program and input parameters for the "command" "args" and the value of
the input shift + command + b, you can build a successful, generate an executable file "filename" .out
third step:
[⇧⌘P] Open the command mode, select [Debug: Open launch.json] command, the selected template is C / C ++, the carriage will automatically generate a file in .vscode launch.json directory, are given below brother file example:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "c/c++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "build c++",
"logging": {
"trace": true,
"traceResponse": true,
"engineLogging": true
}
}
]
}
Completion of these three steps C ++ development environment configured, you can then compile, run, debug C ++ program the
[⇧⌘B] is a compiler, [⇧⌘R] is running the program, if the plug-in installed "Code Runner" can run the program
if you need to debug, then press F5, you can enter debug mode
[⇧⌘B] .out file will be compiled, then [⇧⌘R] operating results are displayed in a terminal window or interact.
Reference article
vscode on mac created using a C ++ project first
Mac to build C / C ++ environment in VSCode