装cygwin 或者mingGW,装gcc工具链,并将cygwin的bin目录加入环境变量PATH中。
ctrl+shift+b
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "gcc",
"command": "g++",
"args": [
"-g ${file}", //指定编译源代码文件
"-o ${fileDirname}/${fileBasenameNoExtension}.exe", // 指定输出文件名,不加该参数则默认输出a.exe
"-ggdb3", // 生成和调试有关的信息
"-Wall", // 开启额外警告
"-static-libgcc", // 静态链接
"-std=c++17", // 使用最新的c++17标准
"-Wno-format",
"-finput-charset=UTF-8",//输入编译器文本编码 默认为UTF-8
"-fexec-charset=GBK"//编译器输出文本编码 自行选择
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always", // 在“终端”中显示编译信息的策略,可以为always,silent,never
"focus": false,
"panel": "shared" // 不同的文件的编译信息共享一个终端面板
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative", "\\"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
//"program": "${file}.exe",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
//"cwd": "${workspaceFolder}",
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"preLaunchTask": "gcc",
"windows": {
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
}
]
}
cuckoo的配置如下,其中参数是从makefile里面提取出来的。
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "i686-w64-mingw32-gcc",
"args": [
"-m32 -Wall -Wextra -std=c99 -static -Wno-missing-field-initializers -I inc/ -I objects/code/ -I src/bson/ -I src/sha1/", //-mwindows
//最后一个参数 -mwindows加上后输出只能出现在cygwin环境,而不会出现在dos环境
"-g",
"${file}",
"-o",
"${workspaceRoot}/test.exe"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
完整版配置环境:
task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "mingw32",
"command": "i686-w64-mingw32-gcc",
"args": [
"-m32 -Wall -Wextra -std=c99 -static -Wno-missing-field-initializers -I inc/ -I objects/code/ -I src/bson/ -I src/sha1/",
"-g ${file}", //指定编译源代码文件
"-o ${fileDirname}/${fileBasenameNoExtension}.exe", // 指定输出文件名,不加该参数则默认输出a.exe
"-ggdb3", // 生成和调试有关的信息
"-Wall", // 开启额外警告
"-static-libgcc", // 静态链接
// "-std=c++17", // 使用最新的c++17标准
"-Wno-format",
"-finput-charset=UTF-8",//输入编译器文本编码 默认为UTF-8
"-fexec-charset=GBK"//编译器输出文本编码 自行选择
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always", // 在“终端”中显示编译信息的策略,可以为always,silent,never
"focus": false,
"panel": "shared" // 不同的文件的编译信息共享一个终端面板
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative", "\\"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
{
"label": "gcc",
"command": "g++",
"args": [
"-g ${file}", //指定编译源代码文件
"-o ${fileDirname}/${fileBasenameNoExtension}.exe", // 指定输出文件名,不加该参数则默认输出a.exe
"-ggdb3", // 生成和调试有关的信息
"-Wall", // 开启额外警告
"-static-libgcc", // 静态链接
"-std=c++17", // 使用最新的c++17标准
"-Wno-format",
"-finput-charset=UTF-8",//输入编译器文本编码 默认为UTF-8
"-fexec-charset=GBK"//编译器输出文本编码 自行选择
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always", // 在“终端”中显示编译信息的策略,可以为always,silent,never
"focus": false,
"panel": "shared" // 不同的文件的编译信息共享一个终端面板
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative", "\\"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "mingw32",
"type": "cppdbg",
"request": "launch",
//"program": "${file}.exe",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
//"cwd": "${workspaceFolder}",
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"preLaunchTask": "mingw32",
"windows": {
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
//"program": "${file}.exe",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
//"cwd": "${workspaceFolder}",
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"preLaunchTask": "gcc",
"windows": {
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
}
]
}
参考:
http://blog.csdn.net/feynman1999/article/details/79437524