Include path issue in PlatformIO workspace

I’m encountering a persistent issue with the include path configuration in my PlatformIO workspace, and I’m seeking assistance in troubleshooting the problem.

Here are the details of my setup and the steps I’ve taken so far:

I have a PlatformIO workspace for my C++ project, which includes multiple source files in the src directory. I created a certificates folder within the workspace to store additional resource files, such as headers and certificates. I added the resources folder to the include path in the .vscode/c_cpp_properties.json file using the following configuration:

{
    "configurations": [
        {
            "name": "PlatformIO",
            "includePath": [
                "[fullpath]/certificates"
            ],
            ...
        }
     "browse": {
             "limitSymbolsToIncludedHeaders": true,
             "path": [
                  "[fullpath]/certificates"
    ],
    ...
}/**",

I also added the include paths in the platformio.ini file as follows:

[env]
src_dir = src
include_dir = include
lib_dir = lib
data_dir = data
test_dir = test
lib_deps_dir = .pio
board = ...
build_flags = 
    -I${workspaceFolder}certificates

Despite these configurations, I’m encountering the error message fatal error: SpotifyCer.h: No such file or directory when trying to compile my main.cpp file. Interestingly, I can resolve the issue by using a relative include path like #include “…/certificates/SpotifyCer.h”, but this is not the desired solution.

Here are the troubleshooting steps I’ve already attempted:

Checked that the SpotifyCer.h file exists in the resources folder and that the filename is correct. Verified that the include directive in main.cpp is correctly specified as #include “SpotifyCer.h”. Confirmed that the paths are correctly added in both .vscode/c_cpp_properties.json and platformio.ini files. Restarted the IDE (Visual Studio Code) to ensure changes are recognized. Checked for hidden characters or formatting issues in the files. Cleaned and rebuilt the project to ensure changes are applied. Unfortunately, none of these steps have resolved the issue.

If anyone has encountered a similar problem with include paths in a PlatformIO workspace or has any suggestions for further troubleshooting, I would greatly appreciate your assistance. Thank you in advance for your help!

Nope, game over. The .vscode/c_cpp_properties.json is auto-generates from your platformio.ini, it’s the source of truth where the build configuration comes from. Your manual changes will be overwritten with the next compile.

I don’t think ${workspaceFolder} is a valid variable that PlatformIO knows about. If the certifciates folder is in the project directory (same level as platformio.ini), you should just say -Icertificates.

Every one of those options is invalid because they can’t be put in [env], they should be in the special [platformio] section per docs. However, since every one of those options gives it the same value as it is already the default, you should delte all these lines.

2 Likes

Hello, I appreciate your response!

I’ve made an attempt to implement the

-Icertificates

as you’ve recommended. However, this resulted in C:/certificates being created in the .vscode/c_cpp_properties.json file. (and thus not working)
While -I${workspaceFolder}certificates creates the correct abs path.

But thanks for the advice on the [env] section! Did not know this

That shouldn’t happen. Where is the project folder located? Not in C:\ directly I guess.

PlatformIO has a variable for the project directory, per docs

https://docs.platformio.org/en/latest/projectconf/sections/env/options/build/build_flags.html#built-in-variables

so you can do

build_flags = 
    -I${PROJECT_DIR}/certificates

Thanks alot!
This effectively resolved my problems.
It’s peculiar how this approach works, while using -I${workspaceFolder}certificates does not.
Interestingly, both methods result in the same paths within the c_cpp_properties.json file.
However, it appears to function only with the build_flag you’ve mentioned in your comment.