vscode include error when remotely debugging c++ program - c++

problem
I'm using vscode to remotely connect to linux server. When I try to debug on my cpp program, which includes these header files under one directory
#include "codec_def.h"
#include "codec_app_def.h"
#include "codec_api.h"
it always come up with an include error:
codec_def.h: No such file or directory
the same error shows up to codec_app_def.h when I comment out the first header file codec_def.h
I have tried
I googled on this problem and find one solution-include path to the c_cpp_properties.json file.
Here is the path screenshot,
path screenshot
and my newly updated c_cpp_properties.json file is like this, I added ${workspaceFolder}/codec/api/svc/ to includePath,
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/codec/api/svc/",
"/usr/include",
"${workspaceFolder}/**",
"${workspaceFolder}/codec/decoder/core/inc",
"/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7",
"/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/x86_64-redhat-linux",
"/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/backward",
"/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/include",
"/usr/local/include",
"/opt/rh/devtoolset-7/root/usr/include"
],
"defines": [],
"compilerPath": "/opt/rh/devtoolset-7/root/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
but I still get the same error and I can't figure out why and how to solve it.
in case of other problems, here are tasks.json file
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/opt/rh/devtoolset-7/root/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/opt/rh/devtoolset-7/root/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /opt/rh/devtoolset-7/root/usr/bin/g++"
}
],
"version": "2.0.0"
}
and 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) run and debug",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [
"/root/compress/losslessh264/tibby.264",
"/fordebug/b.pip"
],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "set up pretty printing",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "set desassembly flavor Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
},
{
"type": "bashdb",
"request": "launch",
"name": "Bash-Debug (select script from list of sh files)",
"cwd": "${workspaceFolder}",
"program": "${command:SelectScriptName}",
"args": []
},
{
"type": "bashdb",
"request": "launch",
"name": "Bash-Debug (simplest configuration)",
"program": "${file}"
}
]
}
I have been stuck in this problems for days, it will be a great help if you know the answer, thank you in advance :)

Related

Errors: "#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit" and "cannot open source file"

I am getting the following errors after setting up C++ on VS Code and running starter code.
OS: MacOS Ventura 13.1 (Intel)
Editor: VS Code.
Compiler: clang++ (default)
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit
cannot open source file "tr1/cwchar" (dependency of "iostream")
Below are my config files (c_cpp_properties, tasks, launch)
c_cpp_properties.json
{
"env": {
"myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
"myCompilerPath": "/usr/local/bin/clang++"
},
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/Cellar/gcc/11.2.0_3/include/c++/11/tr1",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
],
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang++",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "macos-gcc-x64"
}
],
"version": 4}
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/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: clang++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang++ build active file"
}
]
}
The c++ code builds and runs. The error however persists. Anything regarding C++ installation might help.
PS: This is my first time setting up C++.

Debug with F5 fails on VSCode saying "Unable to establish a connection to GDB"

When I press F5 key to run a C++ program on Visual Studio Code, I get the message
"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information."
I use g++.exe and MinGW for compiling.
Until an hour ago, the debugging with F5 key was done properly, and I've never touched launch.json. Could you tell me what is wrong?
Below is the 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 - アクティブ ファイルのビルドとデバッグ",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "gdb の再フォーマットを有効にする",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe アクティブなファイルのビルド"
}
]
}
Below is the tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe アクティブなファイルのビルド",
"command": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "コンパイラ: C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe アクティブなファイルのビルド ver(1)",
"command": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "デバッガーによって生成されたタスク。"
}
]
}
Below is the c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${vcpkgRoot}/x86-windows-static/include",
"C:\\Users\\SonicTheHedgehog\\Desktop\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Addition:
I found an error message on launch.json
Property console is not allowed
and console is marked with wavy line.
Check out this link: https://github.com/microsoft/vscode-cpptools/issues/2889
There is some problem with PowerShell being run as in internal console (running within VSCode).
I made the following change in launch.json:
before:
"environment": [],
"externalConsole": **false**,
"MIMode": "gdb",
after:
"environment": [],
"externalConsole": **true**,
"MIMode": "gdb",
Now, I see the output of the program in cmd.exe outside VSCode. But, the debugger runs fine inside VSCode.
I recommend using a different compiler-based extension such as code runner etc, sometimes, extensions are compatibility issues in visual studio code. I faced the same problem when I started to use visual studio code.

How to Run gtk+ of cpp applicatiion In vscode?

I am working with gtk+ application in cpp ,I want Bastler Pylon integration with gtk and I found by lots of research Gtk+ application uses MinGw compiler and Pylon uses MSVC compiler My problem is to run a gtk+ code into vscode ide,I never used vscode before I usually use sublime text editor in ubuntu and I want above integration in windows....
my four file structure are below...
c_cpp_properties.json
{
"configurations": [
{
"name": "Gtk_dev",
"includePath": [
"${workspaceFolder}/**",
"C:/msys64/mingw64/include/**",
"C:/msys64/mingw64/lib/glib-2.0/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/msys64/mingw64/bin/gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64",
"compilerArgs": [],
"browse": {
"limitSymbolsToIncludedHeaders": false,
"path": []
}
}
],
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\msys64\\mingw64\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc.exe build active file",
"command": "g++",
"args": [
"-g",
"-pthread",
"-mms-bitfields",
"-IC:/msys64/mingw64/include/gtk-3.0",
"-IC:/msys64/mingw64/include/cairo",
"-IC:/msys64/mingw64/include",
"-IC:/msys64/mingw64/include/pango-1.0",
"-IC:/msys64/mingw64/include/fribidi",
"-IC:/msys64/mingw64/include/atk-1.0",
"-IC:/msys64/mingw64/include/lzo",
"-IC:/msys64/mingw64/include/freetype2",
"-IC:/msys64/mingw64/include/libpng16",
"-IC:/msys64/mingw64/include/harfbuzz",
"-IC:/msys64/mingw64/include/pixman-1",
"-IC:/msys64/mingw64/include/gdk-pixbuf-2.0",
"-IC:/msys64/mingw64/include/glib-2.0",
"-IC:/msys64/mingw64/lib/glib-2.0/include",
"${C:/msys64/mingw64/bin/g++}",
"-LC:/mingw64/lib",
"-lgtk-3",
"-lgdk-3",
"-lz",
"-lgdi32",
"-limm32",
"-lshell32",
"-lole32",
"-luuid",
"-lwinmm",
"-ldwmapi",
"-lsetupapi",
"-lcfgmgr32",
"-lpangowin32-1.0",
"-lpangocairo-1.0",
"-lpango-1.0",
"-lharfbuzz",
"-latk-1.0",
"-lcairo-gobject",
"-lcairo",
"-lgdk_pixbuf-2.0",
"-lgio-2.0",
"-lgobject-2.0",
"-lglib-2.0",
"-lintl",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "C:/msys64/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\msys64\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: C:\\msys64\\mingw64\\bin\\g++.exe"
}
]
}
Error showing.................by Pressing for compile and run(ctr+shift+B)..The major problem is there is no mention which file has an error
g++.exe: error: .0: No such file or directory
g++.exe: error: .0: No such file or directory
g++.exe: error: .0: No such file or directory
g++.exe: error: .0: No such file or directory
.....some included files output.....
I ran into the same error yesterday. The error message actually hints at what is wrong (.0). Some of the linked libs (-l) have .0 in their name which seems to be a problem (at least on windows). Putting the respective libs into single quotation marks does the trick:
tasks.json
[...]
"-lcfgmgr32",
"'-lpangowin32-1.0'",
"'-lpangocairo-1.0'",
"'-lpango-1.0'",
"-lharfbuzz",
"'-latk-1.0'",
"-lcairo-gobject",
"-lcairo",
"'-lgdk_pixbuf-2.0'",
"'-lgio-2.0'",
"'-lgobject-2.0'",
"'-lglib-2.0'",
"-lintl",
[...]

Multiple threads open in call-stack of vscode debugger

As you can see in the call stack section, three threads are opened when there is no need for them? I think they are making the process slower. Can someone help me fix this please?
Thank you.
P.S.
Here is my c_cpp_properties.json file:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\MinGW\\lib\\gcc\\mingw32\\9.2.0\\include\\c++"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Here is 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": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"preLaunchTask": "C/C++: cpp.exe build active file",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
And here is my tasks.json file:
{
// 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/C++: cpp.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
I am trying to get vscode working for the first time. I really liked the debugging features and the cool UI but this multiple thread opening everytime is making things difficult. Any help is appreciated.

Visual Studio Code cannot find the g++.exe (Windows 10)

I am setting up the vs code on my windows pc by following this tutorial.
I checked the path is correct by calling g++ from other folder.
But I keep getting this error on vs code:
Cannot find "C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw64\bin\g++.exe".
tried to run g++ helloworld.cpp using command prompt from the folder where helloworld.cpp is located does not give error nor output.
Can anyone show me where I did miss something?
EDIT:
The code is actually compiled already.
It produces a.exe and it runs well.
The problem is I need it to be integrated into vs code.
I guess it is similar like this but I am not sure.
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
tasks.json corrected
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "g++",
"args": [
"-g",
"-o",
"helloworld",
"helloworld.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
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": "g++.exe build active file",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"helloworld",
"helloworld.cpp"
],
"options": {
"cwd": "C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw64/bin/"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
settings.json
{
"[cpp]": {},
"terminal.integrated.shell.windows": "C:\\cygwin64\\bin\\bash.exe"
}
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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw64/bin/g++.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Are you sure the path is correct? Usually if it says it can't find the file, it's because the file isn't there.
When I install MinGW-W64 it goes to C:(...)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32 . So I suppose your path is wrong as the message says (unless you changed it manually): it should not be in mingw64\bin, but in mingw32\bin.
In tasks.json you have
"tasks": [
{
...
"command": "g++",
...
"options": {
"cwd": "C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw64/bin/"
},
...
But you should use your current working directory
"cwd": "${workspaceFolder}"
does it work?
I think your tasks.json should be:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "g++",
"args": [
"-g",
"helloworld.cpp",
"-o",
"helloworld"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
The key part is adding the correct cwd option. In this configuration "helloworld" should be right under your workspaceFolder. If that is not the case update the path for helloworld.cpp accordingly.