0

I am putting together a simple C project in VS Code which would just compile a single C file using GCC compiler.

I have created a c_cpp_properties.json and tasks.json.

It is unclear to me where is the GCC compiler supposed to get include directories from.

When include dirs are added to c_cpp_properties.json via the includePath

"configurations": [
        {
            "name": "Win32",
            "includePath": [
                "C:/include/path1",
                "C:/include/path2"
            ],...

it doesn't work.

It only compiles successfully when I add the paths as compiler arguments to tasks.json:

   "tasks": 
    [
        {
            "label": "Compile C file",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g", 
                "-I",
                "C:/include/path1",
                "-c",
                "myfile.c"
            ],...

Where is the GCC compiler supposed to get include directories from?
What is the includePath in c_cpp_properties.json for?

c_cpp_properties.json Reference Guide says:

  • includePath:
    If "C_Cpp.intelliSenseEngine" is set to "Default" in your settings file, this list of paths will be used by IntelliSense to search for headers included by your source files. This is basically the same as the list of paths you pass to your compiler with the -I switch. If a path ends with /** the IntelliSense engine will do a recursive search for includes starting from that directory. If on Windows with Visual Studio installed, or if a compiler is specified in the compilerPath setting, it is not necessary to list the system include paths in this list.
Danijel
  • 8,198
  • 18
  • 69
  • 133
  • I'm having exactly this problem, did you find by accident a work-around or an actual solution? I'm stuck, like you we're at this time (you describe the problem very well!). – degski Feb 19 '20 at 20:27
  • I did resolve this, however it was a bit long ago. What I remember is that I did NOT specify include paths directly in VS Code files. Instead I created `cpp_properties.json`, `tasks.json` and `launch.json`. In the `tasks.json` I created a task called "Make my app", and there I just called `make`. I already had a `makefile` which I was usualy calling from command line. Here I just called `make` from VS Code instead. All the include paths are inside the `makefile`. Once your "Make my app" is done, you will have `myapp.exe` built. Now write `launch.json` to be able to debug the app from VS Code. – Danijel Feb 20 '20 at 12:43
  • 1
    Hi, thanks for the info, in the meanwhile, I found this: https://stackoverflow.com/a/57734835/646940 which says you have to add the include-folders twice. Well, what can we say, I'm already considering writing my own as the current build thing is not very clever (it, by design does not handle default very nicely. For all my repositories, one default json (in one palace) and one json per project should be enough, the project-json, would just contain the overrides of the default, how hard can it be? And since it's all loosely connected, can easily write some 'glue-builder'. – degski Feb 20 '20 at 17:23

0 Answers0