安装VSCode
1.下载地址: https://code.visualstudio.com/
2. 配置C/C++的编译环境: https://code.visualstudio.com/docs/languages/cpp
VSCode + cygwin + makefile编译C/C++工程
VSCode的task.json 编译.c文件需要一个个将文件添加在 task中,如果文件很多这样并不方便,所有如果文件多的话最好是用makefile编译。
1.代码编译
安装好cygwin,编写好makefile,然后调用make。
方法1: 直接在terminal,调用make
方法2:配置task任务,调用make
task.jason:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}
2. 调试
如果要调试程序,编译代码是CFLAGS标识要加 “-g”,然后配置lauch.jason, 如下
{
// 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”: “(gdb) Launch”,
“type”: “cppdbg”,
“request”: “launch”,
“program”: “
w
o
r
k
s
p
a
c
e
F
o
l
d
e
r
/
m
a
i
n
.
e
x
e
"
,
"
a
r
g
s
"
:
[
]
,
"
s
t
o
p
A
t
E
n
t
r
y
"
:
f
a
l
s
e
,
"
c
w
d
"
:
"
{workspaceFolder}/main.exe", "args": [], "stopAtEntry": false, "cwd": "
workspaceFolder/main.exe","args":[],"stopAtEntry":false,"cwd":"{workspaceFolder}”,
“environment”: [],
“externalConsole”: true,
“MIMode”: “gdb”,
“miDebuggerPath”: “C:\cygwin64\bin\gdb.exe”,
“setupCommands”: [
{
“description”: “Enable pretty-printing for gdb”,
“text”: “-enable-pretty-printing”,
“ignoreFailures”: true
}
]
}
]
}
VSCode + cygwin + cmake编译C/C++工程
- vscode 安装cmake 和cmake tool 。
- 编写 CMakeLists.txt
- 调用cmke, terminal中输入或者编写一个task调用
VSCode 的 优缺点
优点:代码提示好
缺点:不支持重命名的重构,不支持查找reference,截至20190328