Mac下 vscode c/c++ 自动编译配置

本人mac版本10.12.5 ,vscode版本为 1.13

步骤很简单,添加好各种与c++有关的插件后,reload一次,重启vscode。

在helloworld.cpp所在文件夹下创建.vscode文件夹,在.vscode中创建2个文件:tasks.json , launch.json

接着是各个文件的内容:

tasks.json:(编译配置,也就是用cpp生成a.out的过程)


     
     
     
     
  1. {
  2. // See https://go.microsoft.com/fwlink/?LinkId=733558
  3. // for the documentation about the tasks.json format
  4. ”version”: ”0.1.0”,
  5. ”command”: ”g++”, //command 和 args 组合为编译c++命令,即 g++ -g xxx.cpp -o a.out
  6. ”isShellCommand”: true,
  7. ”args”: [ ”-g”, ${file}","-o","a.out"], //${file}代表着任意文件名,代替了helloworld.cpp
  8. ”showOutput”: ”always”,
  9. ”problemMatcher”: { //正则匹配,删除无用符号
  10. ”owner”: ”cpp”,
  11. ”fileLocation”: [ ”relative”, ${workspaceRoot}"],
  12. "pattern": {
  13. "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$”,
  14. ”file”: 1,
  15. ”line”: 2,
  16. ”column”: 3,
  17. ”severity”: 4,
  18. ”message”: 5
  19. }
  20. }
  21. }

launch.json:(调试配置,也就是运行a.out的过程)


     
     
     
     
  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "(lldb) Launch",
  6. "type": "cppdbg",
  7. "request": "launch",
  8. "program": "${workspaceRoot}/a.out", //调试,也就是运行a.out文件
  9. "args": [],
  10. "stopAtEntry": false,
  11. "cwd": "${workspaceRoot}",
  12. "environment": [],
  13. "externalConsole": true,
  14. "MIMode": "lldb",
  15. "preLaunchTask": "g++" //代表执行launch.json前先执行tasks.json中的g++指令
  16. }
  17. ]
  18. }


配置完之后,按f5就能对任意在工作目录下的cpp文件进行一键编译运行调试了


你可能感兴趣的:(编程训练)