It's kind of annoying to have to include project subdirectory paths into the c_cpp_properties.json file as include directories, when they've already been indexed and can be opened with ctrl+p. Can't subdirectories of the current open directory automatically be included as include paths if they contain at least one .h/.hpp file?
It would also be nice if you could optionally include subdirectories of an existing include path. It would come in handy for frameworks like Boost or Qt.
Thank you for the feedback. We agree that manually setting up the includePath is not a good user experience and have been discussing options to make this better for everyone.
One useful addition would be to allow wild cards and paths relative to the loaded file.
e.g
**/include
../include
how about using pkg-config to discover include paths? Just let us pick the package name as dependency. manually running pkg-config and copy pasting include paths into c_cpp_properties.json is tedious. I have written a script which automates this:
pkg-config --cflags-only-I gtkmm-3.0 | sed 's/-I\([^ ]*\)/"\1",\n/g'
We recently added a light bulb code action for unresolved #include files, so you should be able to click your way through most of the include path setup. In a future update we will also add an option to automatically accept all light bulb include path suggestions if they are unambiguous. Another option is to use compile_commands.json so you don't have to mess with the include path or defines. Do either of these options help?
Yes, the compile_commands.json option in particular.
Does anyone know how to get scons to generate compile_commands.json?
Another option is to use compile_commands.json so you don't have to mess with the include path or defines.
That is interesting, but really parsing generated C-compiler command line (e.g., generated by pkg-config) would be the best.
This issue is addressed by the recursive includes feature. Adding ${workspaceFolder}/** to your includePath will auto-add the necessary paths to match your #include lines. You can also use the ** syntax for folders outside the workspace if you are using some other library (like QT) that has a lot of folders that need to be included: /path/to/library/**
Most helpful comment
how about using pkg-config to discover include paths? Just let us pick the package name as dependency. manually running pkg-config and copy pasting include paths into c_cpp_properties.json is tedious. I have written a script which automates this: