Using -I and the full path works fine, -Idir or -I/$PROJECT_DIR does not and result in erroneous paths

Hello, I’m having a strange issue wit -I and -Idir build options, maybe I’m misunderstanding something, but from the manual:

https://docs.platformio.org/en/latest/projectconf/section_env_build.htm

-Idir 	CPPPATH 	Add the directory dir to the list of directories to be searched for header files.

Also I can’t find the doc where the -I flag is explained anymore.

Here’s my platformIO.ini:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino

build_flags =
	;-v; verbose compiling I can't remember why I had to use this once, but I'll keep it here just in case.
	-I/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/headers
	-I/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/interface
	-I/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/types

	-Winline		;Warn when a function marked inline is not inlined.
	;-Wno-reorder	; To ignore warnings about reordering on list initializers.
	-Wno-pointer-arith	; To ignore warnings about casting void pointers, used on a couple of subroutines.
	;-Werror=parentheses	; I can't remember why this is here.

	;-save-temps

Here are the relevant errors in c_cpp_properties.json:

>                 "d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/headers",
>                 "d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/interface",
>                 "d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/types",
>                 "d:/d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/headers",
>                 "d:/d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/interface",
>                 "d:/d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/types",
>                 "d:/Projects/Autodriller-001/Software/AutoDrillerPanel/dir/usr_lib/headers",
>                 "d:/Projects/Autodriller-001/Software/AutoDrillerPanel/dir/usr_lib/interface",
>                 "d:/Projects/Autodriller-001/Software/AutoDrillerPanel/dir/usr_lib/types",

And here’s my full generated c_cpp_properties.json:

//
// !!! WARNING !!! AUTO-GENERATED FILE!
// PLEASE DO NOT MODIFY IT AND USE “platformio.ini”:
// Redirecting...
//
{
“configurations”: [
{
“name”: “PlatformIO”,
“includePath”: [
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/include”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/src”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/headers”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/interface”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/types”,
“d:/d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/headers”,
“d:/d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/interface”,
“d:/d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/types”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/dir/usr_lib/headers”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/dir/usr_lib/interface”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/dir/usr_lib/types”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/cores/arduino”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/variants/mega”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/libraries/HID/src”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/libraries/SPI/src”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/libraries/Wire/src”,
“”
],
“browse”: {
“limitSymbolsToIncludedHeaders”: true,
“path”: [
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/include”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/src”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/headers”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/interface”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/types”,
“d:/d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/headers”,
“d:/d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/interface”,
“d:/d:/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/types”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/dir/usr_lib/headers”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/dir/usr_lib/interface”,
“d:/Projects/Autodriller-001/Software/AutoDrillerPanel/dir/usr_lib/types”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/cores/arduino”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/variants/mega”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/libraries/HID/src”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/libraries/SPI/src”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src”,
“C:/Users/Santiago/.platformio/packages/framework-arduino-avr/libraries/Wire/src”,
“”
]
},
“defines”: [
“PLATFORMIO=50100”,
“ARDUINO_AVR_MEGA2560”,
“F_CPU=16000000L”,
“ARDUINO_ARCH_AVR”,
“ARDUINO=10808”,
AVR_ATmega2560”,
“”
],
“cStandard”: “c11”,
“cppStandard”: “c++11”,
“compilerPath”: “C:/Users/Santiago/.platformio/packages/toolchain-atmelavr/bin/avr-gcc.exe”,
“compilerArgs”: [
“-mmcu=atmega2560”,
“”
]
}
],
“version”: 4
}

When I use the -I flag and add the full path manually vsCode is able to resolve that the libraries are there, but when I use the -Idir flag you can see it adds almost the same pat but it appends a dir/ at the start, also you can see how when i use -I/$PROJECT_DIR it duplicates the drive letter resulting in this d:/d:/

Are all these bugs? or am I not understanding something?

Those look perfectly fine.

The / at the start looks weird, what does it do when you remove that?

Same here.

Paths are relative to the src/ folder of the project project btw. So either use relative paths from there or absolute paths.

1 Like

Removing that seems to have fixed the double drive.

That one actually works fine. (It had always worked before removing it) In fact removing it causes it to do this:
"d:/Projects/Autodriller-001/Software/AutoDrillerPanel/Projects/Autodriller-001/Software/AutoDrillerPanel/usr_lib/headers",

I’m not using the include folder.

The include/ folder is put automatically in the include search path by PlatformIO – that’s it specific purpose :smiley:

Funny story, I moved everything to the include folder (which I had deleted and then recreated, not sure that affects anything) and it doesn’t compile, I suppose it doesn’t like sub-directories inside include? sub-directories inside src do work though.

Also is there any way to do something like -I but for src files?

If source files are to be included in the build process, they must be either in the project’s src/ folder or in a library folder in lib/ and be referenced from the main source code.

Only the top layer (include/) is added, not all subfolders recursively.

Depending on what compilation error it is it might not be caused by the include file.

But I must put headers along inside the same lib folder right?

So I must use -I to include sub-directories on include, which means I still have to manually tell PIO to look for the sub-folders, might as well keep them where they are, good to know for the next time though.

My apologies I should have been more specific it’s not compiling becouse it can’t find the headers for the include

Thanks for all the help.

Conventially yes, unless there’s some really weird strong reason to not do so – MyLib.h should be paired with MyLib.cpp in the same folder.

Yes either -Iinclude/subfolder or reference the header files with their full folder name starting from include/ – for preexisting code not practical though.

1 Like