鱼C论坛

 找回密码
 立即注册
查看: 1949|回复: 9

[已解决]vscode的c配置求助,鱼币答谢

[复制链接]
发表于 2021-2-5 13:38:13 | 显示全部楼层 |阅读模式
5鱼币
我用从网上找了关于vscode配置环境的教程,tasks.json,launch.json如下

tasks.json

tasks.json

launch.json

launch.json

我也没找出什么问题
然后每次一调试就会出现如下报错

报错

报错

好像是c没有编译成功,请各位大佬指点一下
最佳答案
2021-2-5 13:38:14
  1.         {
  2.             "name": "(gdb) 启动",
  3.             "type": "cppdbg",
  4.             "request": "launch",
  5.             "program": "${fileDirname}/${fileBasenameNoExtension}.exe",//测试文件地址
  6.             "args": [],
  7.             "stopAtEntry": false,
  8.             "cwd": "${fileDirname}",
  9.             "environment": [],
  10.             "externalConsole": false,//在内部或外部运行
  11.             "MIMode": "gdb",
  12.             "miDebuggerPath": "D:/minGW/mingw64/bin/gdb.exe",//编译器gdb地址
  13.             "setupCommands": [
  14.                 {
  15.                     "description": "为 gdb 启用整齐打印",
  16.                     "text": "-enable-pretty-printing",
  17.                     "ignoreFailures": true
  18.                 }
  19.             ],
  20.                                 "preLaunchTask": "C/C++: gcc.exe build active file"
  21.         },
复制代码

  1. {
  2.         "version": "2.0.0",
  3.         "tasks": [
  4.                 {
  5.                         "type": "shell",
  6.                         "label": "C/C++: gcc.exe build active file",
  7.                         "command": "D:/minGW/mingw64/bin/gcc.exe",
  8.                         "args": [
  9.                                 "-g",
  10.                                 "${file}",
  11.                                 "-o",
  12.                                 "${fileDirname}\\${fileBasenameNoExtension}.exe"
  13.                         ],
  14.                         "options": {
  15.                                 "cwd": "${fileDirname}"
  16.                         },
  17.                         "problemMatcher": [
  18.                                 "$gcc"
  19.                         ],
  20.                                 "group": {
  21.                                         "kind": "build",
  22.                                         "isDefault": true
  23.                                 }
  24.                 }
  25.         ]
  26. }
复制代码

直接复制就行了(应该没什么问题)

最佳答案

查看完整内容

直接复制就行了(应该没什么问题)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-2-5 13:38:14 | 显示全部楼层    本楼为最佳答案   
  1.         {
  2.             "name": "(gdb) 启动",
  3.             "type": "cppdbg",
  4.             "request": "launch",
  5.             "program": "${fileDirname}/${fileBasenameNoExtension}.exe",//测试文件地址
  6.             "args": [],
  7.             "stopAtEntry": false,
  8.             "cwd": "${fileDirname}",
  9.             "environment": [],
  10.             "externalConsole": false,//在内部或外部运行
  11.             "MIMode": "gdb",
  12.             "miDebuggerPath": "D:/minGW/mingw64/bin/gdb.exe",//编译器gdb地址
  13.             "setupCommands": [
  14.                 {
  15.                     "description": "为 gdb 启用整齐打印",
  16.                     "text": "-enable-pretty-printing",
  17.                     "ignoreFailures": true
  18.                 }
  19.             ],
  20.                                 "preLaunchTask": "C/C++: gcc.exe build active file"
  21.         },
复制代码

  1. {
  2.         "version": "2.0.0",
  3.         "tasks": [
  4.                 {
  5.                         "type": "shell",
  6.                         "label": "C/C++: gcc.exe build active file",
  7.                         "command": "D:/minGW/mingw64/bin/gcc.exe",
  8.                         "args": [
  9.                                 "-g",
  10.                                 "${file}",
  11.                                 "-o",
  12.                                 "${fileDirname}\\${fileBasenameNoExtension}.exe"
  13.                         ],
  14.                         "options": {
  15.                                 "cwd": "${fileDirname}"
  16.                         },
  17.                         "problemMatcher": [
  18.                                 "$gcc"
  19.                         ],
  20.                                 "group": {
  21.                                         "kind": "build",
  22.                                         "isDefault": true
  23.                                 }
  24.                 }
  25.         ]
  26. }
复制代码

直接复制就行了(应该没什么问题)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-2-5 17:07:20 | 显示全部楼层
  1. https://zhuanlan.zhihu.com/p/147366852
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-2-5 17:26:48 | 显示全部楼层

能不能从我的图片上指出错误,我按这个文章改了之后仍有错误提示
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-2-5 17:43:16 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-2-5 17:46:11 | 显示全部楼层
xxm8023 发表于 2021-2-5 17:43
https://fishc.com.cn/forum.php?mod=viewthread&tid=188396
参考一下

能不能帮忙看一下我的launch.json和tasks.json写的哪里有问题
我主要是因为这个没调试成功
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-2-5 18:09:04 | 显示全部楼层
能否把两个文件的内容发一下, 这样也方便调试并找出问题
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-2-5 18:20:50 | 显示全部楼层
PC_ 发表于 2021-2-5 18:09
能否把两个文件的内容发一下, 这样也方便调试并找出问题

test2.c:
  1. #include<stdio.h>
  2. #include<limits.h>

  3. int main(){
  4.     printf("int 内存大小 : %lu \n",sizeof(int));
  5.     return 0;
  6. }
复制代码

tasks.json:
  1. {
  2.         "version": "2.0.0",
  3.         "tasks": [
  4.                 {
  5.                         "type": "shell",
  6.                         "label": "C/C++: gcc.exe build active file",
  7.                         "command": "gcc",
  8.                         "args": [
  9.                                 "-g",
  10.                                 "${file}",
  11.                                 "-o",
  12.                                 "${fileDirname}\\${fileBasenameNoExtension}.exe"
  13.                         ],
  14.                         "options": {
  15.                                 "cwd": "${fileDirname}"
  16.                         },
  17.                         "problemMatcher": [
  18.                                 "$gcc"
  19.                         ],
  20.                         "group": "build"
  21.                 }
  22.         ]
  23. }
复制代码

launch.json:
  1.         {
  2.             "name": "(gdb) 启动",
  3.             "type": "cppdbg",
  4.             "request": "launch",
  5.             "program": "${fileDirname}/${fileBasenameNoExtension}.exe",//测试文件地址
  6.             "args": [],
  7.             "stopAtEntry": false,
  8.             "cwd": "${fileDirname}",
  9.             "environment": [],
  10.             "externalConsole": false,//在内部或外部运行
  11.             "MIMode": "gdb",
  12.             "miDebuggerPath": "D:/minGW/mingw64/bin/gdb.exe",//编译器gdb地址
  13.             "setupCommands": [
  14.                 {
  15.                     "description": "为 gdb 启用整齐打印",
  16.                     "text": "-enable-pretty-printing",
  17.                     "ignoreFailures": true
  18.                 }
  19.             ]
  20.         },
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-2-5 18:40:38 | 显示全部楼层
  1. {
  2.         "version": "2.0.0",
  3.         "tasks": [
  4.                 {
  5.                         "type": "shell",
  6.                         "label": "C/C++: gcc.exe build active file",
  7.                         "command": "[b]gcc[/b]",                               //这里改成你gcc的具体路径, D:/minGW/mingw64/bin/gcc.exe
  8.                         "args": [
  9.                                 "-g",
  10.                                 "${file}",
  11.                                 "-o",
  12.                                 "${fileDirname}\\${fileBasenameNoExtension}.exe"
  13.                         ],
  14.                         "options": {
  15.                                 "cwd": "${fileDirname}"
  16.                         },
  17.                         "problemMatcher": [
  18.                                 "$gcc"
  19.                         ],
  20.                         [b]"group": "build"[/b]
  21.                 }
  22.         ]
  23. }
复制代码


group那里需要加:
  1. "group": {
  2.                                         "kind": "build",
  3.                                         "isDefault": true
  4.                                 }
复制代码

  1.         {
  2.             "name": "(gdb) 启动",
  3.             "type": "cppdbg",
  4.             "request": "launch",
  5.             "program": "${fileDirname}/${fileBasenameNoExtension}.exe",//测试文件地址
  6.             "args": [],
  7.             "stopAtEntry": false,
  8.             "cwd": "${fileDirname}",
  9.             "environment": [],
  10.             "externalConsole": false,//在内部或外部运行
  11.             "MIMode": "gdb",
  12.             "miDebuggerPath": "D:/minGW/mingw64/bin/gdb.exe",//编译器gdb地址
  13.             "setupCommands": [
  14.                 {
  15.                     "description": "为 gdb 启用整齐打印",
  16.                     "text": "-enable-pretty-printing",
  17.                     "ignoreFailures": true
  18.                 }
  19.             ]
  20.         },
复制代码


在这个文件后面加
  1. ,
  2.                                 "preLaunchTask": "C/C++: gcc.exe build active file"
复制代码

(直接复制到那个后面就行了)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-2-5 20:51:28 | 显示全部楼层
PC_ 发表于 2021-2-5 18:40
group那里需要加:

谢谢,把 "preLaunchTask": "C/C++: gcc.exe build active file"这一行加到tasks.json上就能用了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-2 04:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表