I've been reading at almost every question related to include paths in vscode but I just can't solve my issue.
My project folder's custom libraries is in the following path
"/home/gdl/DSS2-DEV/infra"
The infra folder is structured as such:
>Infra
>Include
... some header files
>lib1
>Include
... header files
>src
... cpp files
>lib2
>Include
... header files
>src
... cpp files
So, in order to use any of these libraries, I set up the vscode environment
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [ {"name": "LD_LIBRARY_PATH", "value": "/usr/local/lib:$LD_LIBRARY_PATH" }],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I",
"/home/gdl/DSS2-DEV/infra"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/home/gdl/DSS2-DEV/infra"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
and yet, not a single library can be included:
cpp file
#include <cstdio>
#include <libadm.h>
int main()
{
return 0;
}
Executing task: /usr/bin/g++ -g /home/gdl/DSS2-DEV/infra/parser.cpp -o /home/gdl/DSS2-DEV/infra/parser -I /home/gdl/DSS2-DEV/infra <
/home/gdl/DSS2-DEV/infra/parser.cpp:2:20: fatal error: libadm.h: No such file or directory
#include <libadm.h>
I tried using slashes but it doesn't change a thing. What drives me crazy is that if I CTRL-click the library it actually shows me the header file of that library, meaning that vscode is correctly linking files togheter.
I also tried using quotes instead of brackets for the include but nothing works
Related
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 :)
Note that I'm using Windows 10 x64, MinGW 9.2.0, VSCode 1.54.1.
My goal is to build and run multiple .cpp files in current folder and different levels subfolders I use. I've tried it configuring tasks.json and c_cpp_properties.json files with help of these articles: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
https://code.visualstudio.com/docs/cpp/config-mingw
VS Code will not build c++ programs with multiple .ccp source files
I tried to configure my c_cpp_properties.json by adding this instruction:
"includePath": [
"${workspaceFolder}/*"
]
And I modified also my tasks.json like this:
"args": [
"-std=c++17",
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
]
It actually works for the case I would like to build multiple .cpp files in the main directory. I have a folder vscode_prj, then I have .vscode inside (I attach all my configuration files here), and all files I have inside vscode_prj are build OK, but if I try to create a new folder inside vscode_prj, for example vscode_prj/project1 and I have a few .cpp files inside project1 it's not working and I can't build these files. I just recieve this error:
g++.exe: error: C:\Users\username\folderfolder\_prj\vscode_prj\*.cpp: Invalid argument
g++.exe: fatal error: no input files
compilation terminated.
So, as I understand, compiler just can't find my source files inside subfolder. And it doesn't matter if I have one source file in this folder or several, it's just not build. I appreciate any help and excuse me for my English, it's my first question here, because I just don't know what to do. Thanks.
Attachments:
vscode_prj/.vscode/c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/*"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"compilerArgs": [
"-std=c++17"
]
}
],
"version": 4
}
vscode_prj/.vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-std=c++17",
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\MinGW\\bin\\g++.exe"
}
]
}
vscode_prj/.vscode/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": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Включить автоматическое форматирование для gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
vscode_prj/.vscode/settings.json:
{
"files.associations": {
"*.tcc": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"string": "cpp",
"iomanip": "cpp"
}
}
I've installed OpenCV On Ubuntu successfully and I managed to run a sample code as:
g++ main.cpp -o testoutput -std=c++11 `pkg-config --cflags --libs opencv`
I've tried to run it with Visual Studio Code, I've installed the extension of C/C++ and code runner and ran it with the following configuration:
tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-std=c++11","`pkg-config","--cflags","--libs opencv`"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
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++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": ["-std=c++11","`pkg-config","--cflags","--libs opencv`"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
I got the following error:
[Running] cd "/home/kfir/code/opencv_test/" && g++ main.cpp -o main && "/home/kfir/code/opencv_test/"main
main.cpp:1:10: fatal error: opencv2/core.hpp: No such file or directory
#include <opencv2/core.hpp>
^~~~~~~~~~~~~~~~~~
compilation terminated.
[Done] exited with code=1 in 0.032 seconds
Note: I'm using VSCode on mac and connect Ubuntu remote machine by ssh, the terminal works fine with the command of g++ above
Be sure to add the location to openCV header files in your includePath.
c_cpp_properties.json file :
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${default}",
"~/opencv4.5-custom/include/opencv4"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Mine says "~/opencv4.5-custom/include/opencv4" but it could be "/usr/include/opencv4" or something else, depending on how and where you installed openCV.
You also need to modify task.json to add the arguments to the compiler as given by the pkg-config --cflags --libs opencv4 command, if you would run it in the terminal. You'll need to give the path to the shared object files.
Here's the content of my task.json file :
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I", "~/opencv4.5-custom/include/opencv4",
"-L", "~/opencv4.5-custom/lib",
"-l", "opencv_core",
"-l", "opencv_videoio",
"-l", "opencv_imgproc",
"-l", "opencv_highgui"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
You'll also need the change the paths depending to you setup.
Here I have only included the modules that are used by my program (with the lines "-l", "opencv_core" and so on...) so add or remove modules according to your needs.
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",
[...]
I am learning C++ and I want to use VS Code as my code editor. I created a simple project that has a file with the main method and 2 other files to define a class (a .h and a .cpp). I created the default build task in VS Code to compile my code (g++ build active file), only to get a compile error: undefined reference for the class constructor. I saw that it was related to the linker not finding the implementation because it wasn't included in the build. So I modified my build task to build all .cpp :
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${fileDirname}/*.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
But now when I build the project, I get this error: /path/to/project/*.cpp": No such file or directory. Meaning that *.cpp wasn't interpreted as a wildcard. I am using the default C++ extension for VS Code if is relevant. Am I missing some configuration in my task? How can I make this work? For a large project the method in which I manually add all cpp files as arguments is obviously not appropriate so I would like to make this method to work. Thanks in advace!
This is a tough question to deal with because everyone's computers have different programs, files etc... For reference, I am on windows 10.
This worked for me and it's worth trying...
in tasks.json, either add a new task or modify the existing one to look as follows:
{
"label": "g++.exe build active file",
"args": [
"-g",
"${fileDirname}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
],
"command": "g++.exe",
"options": {
"cwd": "${workspaceFolder}",
},
"group": "build",
"type": "shell"
}
Make a new file under .vscode called c_cpp_properties.json: The following may be different if you are using another compiler or OS
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\msys64\\mingw64\\include\\c++",
"C:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\11.2.0\\include", "${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++20",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Now in launch.json, you need to change the "preLaunchTask" to match the task's name we just created in tasks.json. This will tell vscode to first compile/build the program... then to run it:
Mine now looks like this:
{
"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": "${fileDirname}",
"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": "g++.exe build active file"
}
]
}
Note that the name we chose is not exactly describing what the new task actually does, feel free to change it, but if you do... make sure to update both the "label" in tasks.json and "preLaunchTask" in launch.json to be identical.