PlatformIO Community

Library paths - I don't get it, please help!

Using the Arduino framework on different platforms. I cannot get my projects to compile reliably - I keep moving the header files around, sometimes it works, most of the times it doesn’t, and I seem to miss what I am doing wrong. Would somebody be so kind and point me in the right direction?

This is the structure of my recent project for an Arduino Uno:

main.cpp
include  (DIR)
    \-->font1.h
        font2.h
        gd32v_pjt_include.h (NOT NEEDED FOR ARDUINO)
        gd32vf103_libopt.h (NOT NEEDED FOR ARDUINO)

lib   (DIR)
    \-->lcd_oled (DIR)
        \-->lcd_oled.c (NOT NEEDED FOR ARDUINO)
            lcd_oled.h  (NOT NEEDED FOR ARDUINO)
    \-->oled_6fonts   (DIR)
        \-->oled_6fonts.cpp
            oled_6fonts.h
src  (DIR)
    \-->main.cpp

As you may have noted, there is a private library only needed for another GD32V-based platform which has another display - it is commented out via build_flags and #ifndef in the code.

What I am getting on compiling this.

Dependency Graph
|-- <MIDI Library> 4.3.1
|-- <Bounce2> 2.52
|-- <oled_6fonts>
|   |-- <Wire> 1.0
|-- <Wire> 1.0
Building in release mode
Compiling .pio\build\uno\src\main.cpp.o
Compiling .pio\build\uno\libe43\oled_6fonts\oled_6fonts.cpp.o
In file included from lib\oled_6fonts\oled_6fonts.cpp:40:0:
lib\oled_6fonts\oled_6fonts.h:15:22: fatal error: oledfont.h: No such file or directory
******************************************************************
* Looking for oledfont.h dependency? Check our library registry!

What am I doing wrong? Tried setting the lib_ldf_mode=chain+ but that did not help. Tried removing any header file from the code files, apart from the eponymous header files, but it did not help. Only moving around the headers and reattaching them to the code seems to help sometimes, but I see no system in it. I guess the solution is extremely simple - but I need help.

So where is this file? In your directory listing I only see oled_6fonts.h

Can you show the code surrounding the inclusion of this file?

1 Like

I am sorry for being misleading - that is the font1.h file in the include directory (I renamed it in the diagram for clarity). It is there, but the system does not see it

1 Like

Include section of main.cpp loads oled_6fonts.h:

#include <Arduino.h>
#include <MIDI.h>
#include <Bounce2.h>
#ifndef IS_LONGAN
// This is my little display library. 
// Does smooth'ish characters of up to 24x24px via the Scale2x/Scale3x algorithm
#include <oled_6fonts.h>
#endif
#ifdef IS_LONGAN
#include "gd32v_pjt_include.h"
#include "gd32vf103_libopt.h"
#include "lcd_oled.h"
#endif  

Include section of oled_6fonts.h:

#ifndef OLED_data_H
#define OLED_data_H
#include "oledfont.h"
#include "8x8_vertikal_LSB_2.h"
#include <Arduino.h>
#include <Wire.h>
#include <avr/pgmspace.h>

platformio.ini:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_ldf_mode = chain+
build_flags = -D IS_DUINO=1
 
[env:sipeed-longan-nano]
platform = gd32v
board = sipeed-longan-nano
framework = arduino
upload_protocol = dfu
debug_tool = sipeed-rv-debugger
build_flags = -D IS_LONGAN=1

So the library code uses an include file from the include folder of the project? That doesn’t look structurally good. A library shall not depend on its needed header files being in the user project. Where are the font header files needed? In both libraries or only be one? If it’s only needed by one, then move it to the library folder in need of the file. The main.cpp file can still see the files no problem.

Alternatively you can try to affect the global build settings by adding -I include to the build_flags collection so that it may be found at the compile time of the the libraries.

1 Like

I will try that - I kind of assumed that the Include directory is precisely where headers should go, as it is indeed needed by the alternative libraries I use for uno or gd32 compilation.

Thank you @maxgerhardt for all the effort and help in this forum!

1 Like