0


配置vscode的C/C++环境

一、下载g++

官网:News - nuwen.net

解压下载的文件

二、配置环境变量

进入g++的bin文件复制路径

win+r打开运行对话框

输入** sysdm.cpl **打开系统属性

点击高级

点击环境变量

双击用户变量里的path

新建

把复制的bin文件地址复制进去

再点三个确定

三、安装插件

在扩展中搜索并下载

下载图中的插件

四、调式配置

在自己想要的任意位置创建一个文件夹

比如在D盘创建一个 vscode_c_file文件夹

在创建的 vscode_c_file 文件夹里面创建文件夹

.vscode (一定要创建)

其他文件夹根据实际情况创建

在 .vscode文件夹里面创建四个文件(注意文件后缀)

可以在vscode中右键.vscode文件夹进行创建

  1. c_cpp_properties.json
  2. launch.json
  3. settings.json
  4. tasks.json

然后找到g++.exe文件地址

可以在终端使用 where g++找到

四个文件内容如下:

首先是c_cpp_properties.json

其中compilerPath这一项要把路径改成刚才g++的安装路径:找到刚刚的安装文件夹D:\gcc_release\mingw64\bin\g++.exe,然后复制或者手动把g++.exe的路径敲上去,格式要跟上面代码段一样

  1. {
  2. "configurations": [
  3. {
  4. "name": "Win64",
  5. "includePath": ["${workspaceFolder}/**"],
  6. "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
  7. "windowsSdkVersion": "10.0.18362.0",
  8. "compilerPath": "C:/MinGW/bin/g++.exe",
  9. "cStandard": "c17",
  10. "cppStandard": "c++17",
  11. "intelliSenseMode": "gcc-x64"
  12. }
  13. ],
  14. "version": 4
  15. }

然后是launch.json

注意miDebuggerPath这一项也要把路径改成刚才g++的安装路径:找到刚刚的安装文件夹D:\gcc_release\mingw64\bin\g++.exe ,然后复制或者手动把gdb.exe的路径敲上去,格式要跟上面代码段一样

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "(gdb) Launch",
  6. "type": "cppdbg",
  7. "request": "launch",
  8. "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
  9. "args": [],
  10. "stopAtEntry": false,
  11. "cwd": "${workspaceRoot}",
  12. "environment": [],
  13. "externalConsole": true,
  14. "MIMode": "gdb",
  15. "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
  16. "preLaunchTask": "g++",
  17. "setupCommands": [
  18. {
  19. "description": "Enable pretty-printing for gdb",
  20. "text": "-enable-pretty-printing",
  21. "ignoreFailures": true
  22. }
  23. ]
  24. }
  25. ]
  26. }

然后是settings.json

  1. {
  2. "files.associations": {
  3. "*.py": "python",
  4. "iostream": "cpp",
  5. "*.tcc": "cpp",
  6. "string": "cpp",
  7. "unordered_map": "cpp",
  8. "vector": "cpp",
  9. "ostream": "cpp",
  10. "new": "cpp",
  11. "typeinfo": "cpp",
  12. "deque": "cpp",
  13. "initializer_list": "cpp",
  14. "iosfwd": "cpp",
  15. "fstream": "cpp",
  16. "sstream": "cpp",
  17. "map": "c",
  18. "stdio.h": "c",
  19. "algorithm": "cpp",
  20. "atomic": "cpp",
  21. "bit": "cpp",
  22. "cctype": "cpp",
  23. "clocale": "cpp",
  24. "cmath": "cpp",
  25. "compare": "cpp",
  26. "concepts": "cpp",
  27. "cstddef": "cpp",
  28. "cstdint": "cpp",
  29. "cstdio": "cpp",
  30. "cstdlib": "cpp",
  31. "cstring": "cpp",
  32. "ctime": "cpp",
  33. "cwchar": "cpp",
  34. "exception": "cpp",
  35. "ios": "cpp",
  36. "istream": "cpp",
  37. "iterator": "cpp",
  38. "limits": "cpp",
  39. "memory": "cpp",
  40. "random": "cpp",
  41. "set": "cpp",
  42. "stack": "cpp",
  43. "stdexcept": "cpp",
  44. "streambuf": "cpp",
  45. "system_error": "cpp",
  46. "tuple": "cpp",
  47. "type_traits": "cpp",
  48. "utility": "cpp",
  49. "xfacet": "cpp",
  50. "xiosbase": "cpp",
  51. "xlocale": "cpp",
  52. "xlocinfo": "cpp",
  53. "xlocnum": "cpp",
  54. "xmemory": "cpp",
  55. "xstddef": "cpp",
  56. "xstring": "cpp",
  57. "xtr1common": "cpp",
  58. "xtree": "cpp",
  59. "xutility": "cpp",
  60. "stdlib.h": "c",
  61. "string.h": "c"
  62. },
  63. "editor.suggest.snippetsPreventQuickSuggestions": false,
  64. "aiXcoder.showTrayIcon": true
  65. }

最后是tasks.json

  1. {
  2. "version": "2.0.0",
  3. "tasks": [
  4. {
  5. "label": "g++",
  6. "command": "g++",
  7. "args": [
  8. "-g",
  9. "${file}",
  10. "-o",
  11. "${fileDirname}/${fileBasenameNoExtension}.exe"
  12. ],
  13. "problemMatcher": {
  14. "owner": "cpp",
  15. "fileLocation": ["relative", "${workspaceRoot}"],
  16. "pattern": {
  17. "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
  18. "file": 1,
  19. "line": 2,
  20. "column": 3,
  21. "severity": 4,
  22. "message": 5
  23. }
  24. },
  25. "group": {
  26. "kind": "build",
  27. "isDefault": true
  28. }
  29. }
  30. ]
  31. }

四个文件配置完成

以后的c/c++文件必须放在有 .vscode 文件夹的文件夹里面才能调试否则报错

五、解决无法在只读编辑器编辑

点击vscode左下角的齿轮

点击设置

搜索框输入 interminal

勾选 Run In Terminal 即可

标签: vscode c++ c语言

本文转载自: https://blog.csdn.net/2302_80723133/article/details/143602452
版权归原作者 咕咕咕hu~云 所有, 如有侵权,请联系我们删除。

“配置vscode的C/C++环境”的评论:

还没有评论