I'm trying to code a project in C++ using Visual Studio Code on Ubuntu 22.04.
I need to include a header file that is located in a folder full of other header files and sub-directories (main folder name "depends").
I wrote #include "polar.h"
Visual Studio Code find the header file but it suggested me to add the path in the Include Path on the configuration window of the C/C++ Extension.
I add ${workspaceFolder}/depends/polar-include
but the compiler still says No such file or directory
.
The weird fact is that all the classes and functions from the missing header file are not giving me any errors. I've already tried to using the full path in the #include
tag (so something like #include "depends/include/polar.h"
and the compiler found the file but it gave me a missing file error on a header file linked to the original one.
I've already done this project using QtCreator so I import the Include Path from Qt to VSC but nothing changed.
This is my Include Path:
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}",
"${workspaceFolder}/depends/include/polar-include/**",
"${workspaceFolder}/depends/include/polar-include/modules/**",
"${workspaceFolder}/depends/include/polar-include/modules/stress/**",
"${workspaceFolder}/depends/include/polar-include/b2bInterface/**",
"${workspaceFolder}/depends/include/**"
],
I don't understand why including all the paths as I did in QtCreator doesn't work, as if VSC can't link all the subdirectories and files.
Edit: this is task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
As suggested in the comments, I edited the task.json by adding:
"-I${workspaceFolder}",
"-I${workspaceFolder}/depends/include",
"-I${workspaceFolder}/depends/include/polar-include",
"-I${workspaceFolder}/depends/include/polar-include/b2bInterface",
"-I${workspaceFolder}/depends/include/polar-include/modules",
"-I${workspaceFolder}/depends/include/polar-include/modules/stress",
"-L${workspaceFolder}/depends/lib/Linux_x86_64",
"-lusb-1.0",
"-lprotobuf",
"-lb2bInterfaceCpp",
"-lb2bInterface"
Now it works.