On trying to debug a C++ code on VSCode, I am getting the error, "No client URI found in getBuildTasks()"
I am an absolute beginner and am just learning C++ and just set up my VSCode from a tutorial to run C++ on VSCode with minGW-w64. But the debug button just won't work like it should have and is instead throwing that error.
This is what my launch.json looks like:
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"preLaunchTask": "echo",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
And these are the options that show up when I press Run and Debug with a.cpp opened in the folder with the .vscode subfolder containing the aforementioned launch.json file along with c_cpp_properties.json and tasks.json files.
Any and all help will be appreciated.
You need to open the Folder that you're working in, into the Workspace.
To do this, select Explorer from the left side bar and click on the big blue Open Folder button over there and open the Folder that you're working on and containing the .vscode subfolder.
.
.
The Desktop is where I build most of my smaller, quicker programs at. I removed the Desktop from the WorkSpace open, in order to stop the Source Control from suggesting me to commit changes to GitHub and hence VSCode had no directory to find the .vscode folder from. This never was a problem when I would debug and run python files but for C++ it was.
It was an absolute nooby dumbo mistake of mine but it literally took me 2 days to figure out and I've written the answer down, hoping it helps some other noob. :)
Related
Environment
Ubuntu 20.04.
VS Code 1.69.0 with extensions
VS Code launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Test debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/bazel-bin/app/mp_test",
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
}
]
}
Note: I use bazel to build mediapipe and my app. Do not know if it matters or not.
bazel build --copt="-g" --strip="never" --define MEDIAPIPE_DISABLE_GPU=1 //app:mp_test
Problem description
I have a code:
mediapipe::CalculatorGraph graph;
graph.Initialize(config);
I set breakpoints on the second line. Start debugging. After F11 (step into) execution cursor stands on the line. I repeated several time F11 and at the end it goes into some standard library code (unique_ptr exactly). I tried to use Stack Trace and double click on one of its entries. Look at the screenshot. So, debugger cann't open the source file, because it looks into /proc/self/cwd/external folder which doesn't exists. Meanwhile IntelliSence can find the definition of the mediapipe::CalculatorGraph::Initialize in mediapipe project directory and my app was built successfully, means that compiler (linker) found everything. Why? How can I fix it?
Note: Folder /proc/self/cwd/ contains files from my app folder (BUILD, main.cpp, ...).
Hi i recently started using VS code for my C++ course. I am trying to get the debugger to work but even with hours of trying to figure out what's wrong i still get the following error "Unable to start debugging. Not implemented." I am a bit unsure on what that means let alone how to solve it. My launch.json file looks like this. Thank you in advance for the help.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "Assigment_1.C++",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal"
}
]
}
I don't have enough Karma to post in the comment thread but I wanted to say that I don't think it matters that you're using vs code instead of visual studio. It says in the debug console that the C/C++ extionsion is compatible with both, and this is the .json that is automatically generated by vs code. I'm having the same issue trying to run C. I've reached out to microsoft support. Let me know if you've figured it out, thanks.
Alternatively, it seems to work if you just download the code runner extension and then right click and choose run code instead. At least it did for me using C. Still trying to figure out how to use it with the debugger however.
I had the same problem and I have solved this problem using these steps.
First create your C++ folder (mine is cpp test) and create the main.cpp file.
Then after making the main method just click f5 and the vs code will pop up a box asking whether C++(GDB) or C++(Windows).
refer the photo
Now click on C++(GDB/LLDB).
Now click on g++.exe (Build and Debug active file).
Now the vs code will generate the lanch.json file.
Then go to the main.cpp file, Just click f5 and it will run without any problem. It worked for me.
(Please make sure that you have installed cygwin64 on your computer, mingw is also possible)
The json file below worked for me
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/mingw/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
I've installed WSL2 and build tool and everything is working well on linux console (including a test c++ program I was able to debug with dbg).
I'm now trying to have a working development environment on my windows10 machine, by installing VSCode and a couple of extensions (c/c++ and Remote WSL).
Build works just fine, but when I try to debug, after executing (F10) a couple of lines I get the error:
Unable to open 'libc-start.c': Unable to read file 'vscode-remote://wsl+ubuntu-20.04/build/glibc-YYA7BZ/glibc-2.31/csu/libc-start.c' (Error: Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu-20.04/build/glibc-YYA7BZ/glibc-2.31/csu/libc-start.c').
From that point on debugger basically doesn't work anymore, every time I press F10 (or F11) I get a new popup with the same error
screenshot of error and dev environment
Pressing the "Create File" button results in an "Unable to write file 'vscode-remote://wsl+ubuntu-20.04...." (same file as above).
here following my launch.json file
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
and my tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C++ Compile",
"command": "/usr/bin/g++",
"args": ["-g","*.cpp","-o","${fileDirname}/${fileBasenameNoExtension}"],
"options": {"cwd": "${workspaceFolder}"},
"problemMatcher": ["$gcc"],
"group": {"kind": "build","isDefault": true}
}
]
}
I've searched quite a bit before posting. Other have had similar problems in older posts but most of them claimed that being an old bug and they say the problem was solved with the upgrade. I'm running latest version of everything I'm using (including VSCode and the plugins).
thank you in advance to anyone helping out.
Adding
"sourceFileMap": { "//wsl$/Ubuntu-20.04" : "/" }
to the launch.json resolved the problem for me.
I was following the documentation on https://code.visualstudio.com/docs/cpp/config-mingw to set up my C++ development environment on VS code.
I succesfully created my build task and ran my build task, but when i tried to set up my debugger (GDB debugger), i got the following output on the terminal.
C:\Users\Ayon\c++\helloworld> cmd /C "c:\Users\Ayon\.vscode\extensions\ms-vscode.cpptools-0.28.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-shlwrnf5.x12 --stdout=Microsoft-MIEngine-Out-vg12hskh.c52 --stderr=Microsoft-MIEngine-Error-nrcvh0zz.0u0 --pid=Microsoft-MIEngine-Pid-m1nmxyvs.qk2 --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "
'cmd' is not recognized as an internal or external command,
operable program or batch file.
Im curious as to how the "cmd /" came about in the output. Please help me fix this error.
Thanks in advance.
For reference, here is my launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
Did you add mingw64/bin to your system path? Here's how to do so:
Control panel -> Edit path -> Environment variables -> Path -> New
You can also find more guidance on
vscode official website.
I believe the problem is with the MinGW installation. I also faced this problem for a long time, solved it by doing the following:
Completely removing the current MinGW Video tutorial
Installing MinGW-w64 from the site mentioned in vscode documentation. installation video tutorial
After this, I followed the configuration mentioned in this video. The video is for c code, but you can make the required changes to c++ code. Now I'm able to debug in vscode.
By this way, you will also be able to use the latest versions of gdb and g++ available.
I'm trying to do remote debugging of bazel project in docker.
Local plugins: Remote Development
Docker plugins (defined in devcontainer.json): ms-vscode.cpptools
My launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"MIMode": "gdb",
"request": "launch",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"program": "/root/.cache/bazel/_bazel_root/e53bbb0b0da4e26d24b415310219b953/execroot/tf_serving/bazel-out/k8-dbg/bin/tensorflow_serving/fplugin/fserve_cc",
"externalConsole": false,
}
]
}
However I'm getting an error:
Unable to open 'fserve.cc': Unable to read file 'vscode-remote://dev-container+2f55736572732f6d67756d6f77736b2f776f726b2f6f766d732d63/proc/self/cwd/tensorflow_serving/fplugin/fserve.cc
In local development I would add sourceFileMap, however it doesn't seem to work for remote docker development. Any ideas?
when you try to compile with bazel, you will have 4 soft link(bazel-bin, bazel-{source-folder}, bazel-out, bazel-testlog)
modify this attribute wi
"cwd": "${workspaceFolder}/bazel-",
I'm not sure that your problem is due to remote debugging. I believe that the following info will work whether or not you're in a remote environment.
Bazel generates a few symlinks in your project's root folder that contain useful data (for more see the docs):
bazel-bin is a symlink to a folder in the output directory that contains generated code and binaries for the latest configuration of the build you've run.
bazel-{folder-name} is a symlink to the execRoot, which is how bazel sees your project's source code. {folder-name} is the name of the folder your project is in.
bazel-out is a symlink to bazel's output root.
bazel-testlog is a symlink to the outputs from test runs
If you're not using bazel's runfiles library
To provide VSCode with sources at the right location, modify the "cwd" attribute in launch.json to:
"cwd": "${workspaceFolder}/bazel-{folder-name}",`
If you are using runfiles
You're using runfiles if your program requires files in a data attribute in any of its dependencies
First, set "cwd" to the root of the runfiles tree for your binary, and then set "sourceFileMap" in a way that maps the current working directory to the execRoot symlink. For me (on linux), /proc/self/cwd maps correctly, but that might not be true for you. I was able to tell that I got it wrong because VSCode complained about being unable to read a file at /proc/self/cwd/external/external-project/src/file.cpp.
"cwd": "${workspaceFolder}/bazel-bin/path/to/executable/executable.runfiles/{workspace-name}`,
"sourceFileMap": {
"/proc/self/cwd": "${workspaceFolder}/bazel-{folder-name}`,
},
{workspace-name} can be found in WORKSPACE, it will look like workspace(name = "my-project"). If there is no workspace name defined in that file, it defaults to __main__.
I might also recommend changing the "program" attribute to a more convenient location. If the last thing you did was build your binary with bazel, you can find the built executable at bazel-bin/path/to/executable/executable
A full example:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch Debug",
"type": "cppdbg",
"request": "launch",
// path to the most recently built version of executable
// this should be built with `bazel build -c dbg //path/to:executable`
"program": "${workspaceFolder}/bazel-bin/path/to/executable/executable",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/bazel-bin/path/to/executable/executable.runfiles/{workspace-name}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"sourceFileMap": {
"/proc/self/cwd": "${workspaceFolder}/bazel-{folder-name}"
}
}
]
}
Most of this is covered in this useful post (which also shows how to automatically build your executable using tasks.json):
https://shanee.io/blog/2019/05/28/bazel-with-visual-studio-code/