一、编写原文件及头文件
编写头文件add.h
编写add.cpp
编写main.cpp
按F5,点击C++(GDB/LLDB)
点击g++.exe - 生成和调试活动文件,生成launch.josn文件
再按F5,点击配置任务
或点击运行任务
点击配置任务
点击C/C++:g++.exe build active file生成task.json文件
添加需要的一同编译的文件
{
"tasks": [
{
"type": "shell", \\type类型为“shell”
"label": "C/C++: g++.exe build active file",
"command": "D:\\Program Files\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"${fileDirname}\\add.cpp", \\添加需要一同编译的文件
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Generated task by Debugger"
}
],
"version": "2.0.0"
}
再按F5即可编译。