7

I'm working in VSCode with the C/C++ extension on Ubuntu 18.04.

I'm trying to include gmodule.h and it raises the error gmodule.h: No such file or directory on line 2, character 10 of the main file.

So, the problem lies with gmodule.h being not in /usr/include but in /usr/include/glib-2.0. Realizing this, I added this folder to the includePath variable in c_cpp_properties.json. However, it still raises the same error.

When using #include <glib-2.0/gmodule.h> instead of #include <gmodule.h>, it does work but this only shifts the problem to gmodule.h itself, as other includes that lie in the glib-2.0 folder still don't work inside of gmodule.h.

All in all, the problem is that add to the includePath in c_cpp_properties.json doesn't change anything and I want to know how to make this work, since I would like to use gmodule.

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "/usr/include/glib-2.0/*"
            ]
        }
    ],
    "version": 4
}

for now I'm just trying to include gmodule.h and not do anything with it yet, so this is my main file:

#include <stdio.h>
#include <gmodule.h>

int main() {
    printf("hai\n");
    return 0;
}
Kelvin Bouma
  • 179
  • 1
  • 2
  • 12
  • have you tried `#include ` instead? – Waqar Apr 07 '20 at 12:11
  • Yes I have, I even put the results in this post: "When using #include instead of #include , it does work but this only shifts the problem to gmodule.h itself, as other includes that lie in the glib-2.0 folder still don't work inside of gmodule.h." – Kelvin Bouma Apr 07 '20 at 12:13
  • Where exactly do you see the error message? Consider adding a screenshot of it. Also, have you tried removing the `/*` from the `includePath` entry? – Scott McPeak Apr 07 '20 at 13:18
  • yes I have tried that, and I just added that the error occurred on line 2, character 10 of the main file – Kelvin Bouma Apr 07 '20 at 16:35

5 Answers5

13

The c_cpp_properties.json controls, among other things, where intellisense in the IDE resolves include files. The IDE and the build tasks are independent things and as a result, configured and operate independently in VS Code.

The solution to your problem is to add the include path to your tasks.json file, as follows:

"args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}",
        "--include-directory=/usr/include/glib-2.0/"
 ],
Dodgyrabbit
  • 3,107
  • 3
  • 26
  • 28
  • 1
    Thanks for you answers which help me solve the problem. Before that, I just can not figure out why the problem existed when I add "includePath" in c_cpp_properties.json. The answers help me understand VSCODE and C program better. Thanks again – dq.shen Jun 04 '21 at 12:16
3

What solved it for me was to just type folder path without /* or /** Then it prompted me if I want to enable Intellisense for this folder and I allowed it and it worked.

bko
  • 96
  • 3
  • Thanks. It works. On windows 10 I included eigen3 so: "includePath": [ "${workspaceFolder}/**", "C:/Program Files (x86)/Eigen3/Include/eigen3/" ], – AndrewPt Mar 20 '23 at 09:01
2

I had the same issue, and it was caused by the configurationProvider option in the c_cpp_properties.json file pointing to a disabled makefile-tools plugin. The makefile-tools plugin was correctly generating the list of include paths, but these paths were not included in the final list of include paths for Intellisense, because the plugin was disabled. In my case, the solution was either remove that configuration option or enable the makefile-tools plugin.

Honza Vojtěch
  • 685
  • 1
  • 7
  • 27
2

Issue:

Thanks all! This pointed me in the right directions. I was getting an error not finding the WxWidgets library. The "configurationProvider" issue seems to be the problem.

I do have "makefile-tools" installed and the "configurationProvider" pointed to it, so not sure why there was an issue.

For this solution, I also had tried forcing the include directories in the "includePath" with no success as per the original issue.

My project is using CMake, but the "configurationProvider" was pointing to "makefile-tools" for whatever reason. I removed the forced "includePath" paths and pointed "configurationProvider" to "ms-vscode.cmake-tools". This seemed to fix my issue after reopening the project.

Solution:

ctrl-shift-p
C/C++: Change Configuration Provider...
Select "CMake Tools"
Exit VSCode
Start VSCode
AtesComp
  • 431
  • 3
  • 5
1

I managed to make IntelliSense work by adding two paths for glib as reported by pkg-config:

$ pkg-config --cflags glib-2.0
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include

.vscode/c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/glib-2.0/**",
                "/usr/lib/x86_64-linux-gnu/glib-2.0/include/**"
            ],
            "defines": [],
            ...
        }
    ],
    ...
}