VScode远程调试问题 launch: program ‘ ‘ does not exist 解决

经过远程连接之后,写下main.cpp进行调试

//main.cpp
#include<iostream>
using namespace std;
int main()
{

    cout<<"hello world"<<endl;
    return 0;
}

//launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C/C++ Runner: Debug Session",
      "type": "cppdbg",
      "request": "launch",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}", // gdb程序的工作目录
      "environment": [],
      "program": "${workspaceFolder}/main",,
      "internalConsoleOptions": "openOnSessionStart",
      "MIMode": "gdb",
      "miDebuggerPath": "/usr/bin/gdb",
      "externalConsole": false,
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}
//tasks.json
{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "shell",
			"label": "gnss-sdr-lizw0.0.01",
			"command": "g++",
			"args": [
				"-g",
				"main.cpp",
				"-o",
				"main"
			]
			//"group": "build"
		}
		
	]
}

出错error

如果按F5 出现 ”launch: program ’ ’ does not exist “这个问题 ,首先看launch.json 里面的 “cwd” , “program” 和 tasks.json里的”args“能否对上,这在其他博主的blog里已经讲了,,那么如果还没解决就需要在launch.json 里加入
“preLaunchTask”: “gnss-sdr-lizw0.0.01” // 该项的值对应任务文件中的label的值,表示在执行debug前先执行编译任务
"gnss-sdr-lizw0.0.01"和tasks.json里的"label"名字相同。
之后的launch.json文件是这样的:

//launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C/C++ Runner: Debug Session",
      "type": "cppdbg",
      "request": "launch",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}", // gdb程序的工作目录
      "environment": [],
      "program": "${workspaceFolder}/main",,
      "internalConsoleOptions": "openOnSessionStart",
      "MIMode": "gdb",
      "miDebuggerPath": "/usr/bin/gdb",
      "externalConsole": false,
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "gnss-sdr-lizw0.0.01" // 该项的值对应任务文件中的label的值,表示在执行debug前先执行编译任务
    }
  ]
}

原理很简单,先编译成可执行文件,才能用gdb调试,这一行就是告诉编译器,先编译再调试。
好了,加上这一行之后非常顺利的解决了!!可以调试了!!

另外还有个问题一直没解决,我把launch.json里的"externalConsole": false,改为"externalConsole": true,之后为什么还是不能显示外部终端那个黑框呢,难道是远程连接的模式就是不能显示嘛?目前只能用字符终端看啦,不过也好凑合是能调试了!!

参考: vscode远程调试

  • 3
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值