How to use relative paths in build flags?

Hi,
How can I use a path relative to workspace_dir as a build flag?

I am trying to add include folders. Eg: I would like to do the following:
build_flags =
-I ${workspace_dir}/utils/segger_rtt/RTT

Please let me know, the docs are not very clear on this and I tried different things without success
Thanks

1 Like

Just use -I utils/segger_rtt/RTT, PlatformIO will automatically resolve path from a current working directory (which is project directory).

1 Like

This does not work when using the Native platform.

build_flags = 
	-Ilib/custom_arduino_fakes/

When checking the verbose output of the compilation, I see that it is always translated into the following:

-IC:\Users\ME\.platformio\platforms\native\builder\lib\custom_arduino_fakes\

Which is of course not the path of my project.

Only passing the absolute full path gets translated to the correct relative path, so this:

build_flags = 
	-IC:/Users/ME/Development/PROJ/Firmware/lib/custom_arduino_fakes/

gets translated into this:

-Ilib/custom_arduino_fakes/

Trying to access the default variables did not work because they were always empty here in this context for some reason I do not know.

Do you have any suggestion to be able to use a relative path inside my project here without needing to pass the whole absolute path?

1 Like

Well, I found out how to get it working, for me I needed quotation marks to get it working. So just like this:

build_flags =
    ; -I "${platformio.workspace_dir}/../" ; This accesses the current project directory
    -I "${platformio.lib_dir}/arduino_fakes/src/core"

Without these quotations it did not work.

1 Like