当前位置:   article > 正文

VSCode配置C语言编译环境_vscode选择编译器

vscode选择编译器

一、下载C语言编译器

(1)下载地址:MinGW-w64 - for 32 and 64 bit Windows - Browse /mingw-w64 at SourceForge.net

下载如下的windows版本:

 (2)配置环境变量:

 二、安装VSCode

三、配置VSCode

(1)安装C/C++插件:

 (2)配置文件:新建.vscode文件夹,文件夹下新建如下三个文件

 1、c_cpp_properties.json

  1. {
  2. "configurations": [
  3. {
  4. "name": "Win32",
  5. "includePath": [
  6. "${workspaceRoot}",
  7. "D:\\software\\mingw64"
  8. ],
  9. "defines": [
  10. "_DEBUG",
  11. "UNICODE",
  12. "__GNUC__=6",
  13. "__cdecl=__attribute__((__cdecl__))"
  14. ],
  15. "intelliSenseMode": "windows-gcc-x64",
  16. "browse": {
  17. "limitSymbolsToIncludedHeaders": true,
  18. "databaseFilename": "",
  19. "path": [
  20. "${workspaceRoot}",
  21. "D:\\software\\mingw64"
  22. ]
  23. },
  24. "compilerPath": "D:\\software\\mingw64\\bin\\gcc.exe",
  25. "cppStandard": "c++17"
  26. }
  27. ],
  28. "version": 4
  29. }

2、launch.json

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "(Windows) Launch",
  6. "type": "cppvsdbg",
  7. "request": "launch",
  8. "program": "cmd",
  9. "preLaunchTask": "echo",
  10. "args": [
  11. "/C",
  12. "${fileDirname}\\${fileBasenameNoExtension}.exe",
  13. "&",
  14. "echo.",
  15. "&",
  16. "pause"
  17. ],
  18. "stopAtEntry": false,
  19. "cwd": "${workspaceFolder}",
  20. "environment": [],
  21. "externalConsole":true
  22. },
  23. {
  24. "name": "(gdb) Launch",
  25. "type": "cppdbg",
  26. "request": "launch",
  27. "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
  28. "args": [],
  29. "stopAtEntry": false,
  30. "cwd": "${workspaceFolder}",
  31. "environment": [],
  32. "externalConsole": true,
  33. "MIMode": "gdb",
  34. "miDebuggerPath": "D:\\software\\mingw64\\bin\\gdb.exe",// 自己电脑的gdb
  35. "preLaunchTask": "echo",//这里和task.json的label相对应
  36. "setupCommands": [
  37. {
  38. "description": "Enable pretty-printing for gdb",
  39. "text": "-enable-pretty-printing",
  40. "ignoreFailures": true
  41. }
  42. ]
  43. }
  44. ]
  45. }

3、tasks.json

  1. {
  2. // See https://go.microsoft.com/fwlink/?LinkId=733558
  3. // for the documentation about the tasks.json format
  4. "version": "2.0.0",
  5. "tasks": [
  6. {
  7. "label": "echo",
  8. "type": "shell",
  9. "command": "gcc",
  10. "args": [
  11. "-g",
  12. "${file}",
  13. "-o",
  14. "${fileBasenameNoExtension}.exe",
  15. "-fexec-charset=GBK"
  16. ]
  17. },
  18. {
  19. "type": "cppbuild",
  20. "label": "C/C++: gcc.exe 生成活动文件",
  21. "command": "D:\\software\\mingw64\\bin\\gcc.exe",
  22. "args": [
  23. "-fdiagnostics-color=always",
  24. "-g",
  25. "${file}",
  26. "-o",
  27. "${fileDirname}\\${fileBasenameNoExtension}.exe"
  28. ],
  29. "options": {
  30. "cwd": "D:/software/mingw64/bin"
  31. },
  32. "problemMatcher": [
  33. "$gcc"
  34. ],
  35. "group": "build",
  36. "detail": "编译器: D:\\software\\mingw64\\bin\\gcc.exe"
  37. }
  38. ],
  39. "presentation": {
  40. "echo": true,
  41. "reveal": "always",
  42. "focus": false,
  43. "panel": "shared",
  44. "showReuseMessage": true,
  45. "clear": false
  46. }
  47. }

三、测试

新建文件test.c,复制如下测试代码,按F5运行

  1. #include <stdio.h>
  2. #include <windows.h>
  3. int main()
  4. {
  5. printf("Hello World\n");
  6. system("pause");
  7. return 0;
  8. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/793271
推荐阅读
相关标签
  

闽ICP备14008679号