0

I have been trying for a while to add an additional include path to Arduino compiler (in VS-Code) to be able to compile my project that has header and source files distributed in different levels of folders.

Including the directories I want in the includePath in c_cpp_properties.json is not enough because this includePath is used only for the IntelliSense (and apparently that is right because I am not able to compile, because the header files cannot be found, even though the IntelliSense works).

The only hope I found is to pass an additional flag -I to the compiler, this is what I tried to do (I tried both using the workspace variable and the absolute path, but none worked):

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "C:\\Users\\MYUSER\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**",
                "C:\\Users\\MYUSER\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.7.4\\**",
                "${workspaceFolder}\\include\\**"
            ],
            "compilerPath": "C:/Program Files (x86)/Arduino/hardware/tools/avr/bin/avr-gcc.exe",
            "forcedInclude": [],
            "intelliSenseMode": "clang-x64",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "compilerArgs": [    <<===== Trying to pass the include path to the compiler.
                "-I${workspaceFolder}/include",
                "-IC:/Users/MYUSER/MYPROJECT/Firmware/include"
            ]
        }
    ],
    "version": 4
}

But my tries did not work, I am still not able to compile, because the compiler cannot find the header files. Using the absolute path of the header files directly in my CPP code is not an option.

What am I doing wrong? Could anyone please help me to be able to pass the include paths to the compiler successfully?

UPDATE

Checking the output of compilation in verbose mode shows that the paths I tried to include are not considered (there didn't present in the output at all). I am not sure why they are ignored...

5
  • try changing "name": "Win32", to "name": "Arduino",
    – jsotola
    Oct 30 '20 at 18:01
  • @jsotola nope, sorry that did not help. Oct 30 '20 at 18:12
  • download process monitor from microsoft, run it and then compile your code ... the process monitor will log all disk reads that the compiler does ... that will tell you if your cofig file is being read and also where the compiler is looking for includes ... docs.microsoft.com/en-us/sysinternals/downloads/procmon ... there is a lot of useful utils at that site
    – jsotola
    Oct 30 '20 at 18:33
  • one other quick and dirty test is to put garbage into the config file ... if the compiler does not complain, then it probably does not read the config file
    – jsotola
    Oct 30 '20 at 18:35
  • @jsotola thank you for your reply, I tried the tool, I have been investigating the platform.txt file, this file seems to be needed, because deleting it causes the VS Code to complain when trying to compile, and in this file I can in theory add some extra flags, but for some reason I still cannot compile because the headers cannot be found... Oct 30 '20 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.