使用cygwin的Visual Studio代码(不工作)

问题描述:

我刚刚安装了VSCode(在Windows上),并且我正在尝试使用cygwin运行C编译器。我关注此页面:https://code.visualstudio.com/docs/languages/cpp。我的c_cpp_properites.jsonlaunch.json文件很好。我认为这是我的tasks.json文件问题:使用cygwin的Visual Studio代码(不工作)

{ 
// See https://go.microsoft.com/fwlink/?LinkId=733558 
// for the documentation about the tasks.json format 
"version": "2.0.0", 
"tasks": [ 
    { 
     "taskName": "Build test", 
     "type": "shell", 
     "command": "g++", 
     "args": [ 
      "-g", 
      "test.c" 
     ], 
     "group": { 
      "kind": "build", 
      "isDefault": true 
     }, 
     "problemMatcher": [] 
    } 
] 
} 

我只是想运行一个simple Hello World program。任务运行,如终端所示:

执行任务:g ++ -g test.c <终端将被任务重用,按任意键关闭它。

并没有什么东西显示在输出端。我可以从cmd运行a.exe文件,它可以工作,但我宁愿将输出打印在VSCode中。

是的,该行为是由设计。除非你告诉它,否则构建任务不打算运行你构建的程序。对于该功能,您需要转向调试器。

因为您已经在Cygwin上安装了g++,所以我假设还安装了gdb。点击VS Code左侧的调试选项卡,点击下拉菜单,然后选择Add Configuration,然后从刚打开的launch.json文件的下拉列表中选择C/C++: (gdb) Launch将为您设置空白gdb配置。

Blank gdb launcher

然后,分别填写"program""miDebuggerPath"与路径a.exe文件和路径gdb可执行文件。

然后,Debug面板中的绿色播放按钮将起作用。当你点击它时,调试会话将开始。

Properly Configured Debug Session