Compiler can't find Headers in lib_deps nor from the arduino framework (only in libs)

My team started to implement some messy code from an older team (dogs)
but the compiler throws an error when ever a Header out side of the “lib” folder should be included.
Because of that we moved libaries from lib_deps to the “lib” folder but I’m growing tired now that even some Arduino libaries aren’t found.

Error msg when compiling

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy40.html
PLATFORM: Teensy (5.0.0) > Teensy 4.0
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 1.94MB Flash     
DEBUG: Current (jlink) External (jlink)
PACKAGES:
 - framework-arduinoteensy @ 1.159.0 (1.59)
 - tool-teensy @ 1.159.0 (1.59)
 - toolchain-gccarmnoneeabi-teensy @ 1.110301.0 (11.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 126 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit BNO055 @ 1.6.3
|-- Adafruit BusIO @ 1.16.1
|-- Adafruit ILI9341 @ 1.6.1
|-- Adafruit TSC2007 @ 1.1.2
|-- TCA9534 @ 0.1.1
|-- Adafruit NeoPixel @ 1.12.3
|-- Adafruit TCS34725 @ 1.4.4
|-- Adafruit_VL6180X @ 1.4.3
|-- General
|-- Timer
Building in release mode
Compiling .pio\build\teensy40\src\main.cpp.o
Compiling .pio\build\teensy40\libb94\Camera\Camera.cpp.o
Compiling .pio\build\teensy40\lib7e2\Movement\Movement.cpp.o
Compiling .pio\build\teensy40\libff8\General\General.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\HardwareSerial3.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\HardwareSerial4.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\HardwareSerial5.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\HardwareSerial6.cpp.o
In file included from lib\Camera\../DogLib/../General/..\Movement\../Adafruit BNO055/Adafruit_BNO055.h:28,
                 from lib\Camera\../DogLib/../General/..\Movement\Movement.h:6,
                 from lib\Camera\../DogLib/../General/General.h:12,
                 from lib\Camera\../DogLib/VarsFromDogs.h:4,
                 from lib\Camera\Camera.h:5,
                 from lib\Camera\Camera.cpp:1:
c:\users\lesee\documents\rag\maze-milbe-test\lib\adafruit busio@1.16.1\adafruit_i2cdevice.h:5:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

    5 | #include <Wire.h>
      |          ^~~~~~~~
compilation terminated.
*** [.pio\build\teensy40\libb94\Camera\Camera.cpp.o] Error 1
In file included from lib\Movement\../DogLib/VarsFromDogs.h:4,
                 from lib\Movement\Movement.h:8,
                 from lib\Movement\Movement.cpp:1:
lib\Movement\../DogLib/../General/General.h:42:5: error: 'Movement' does not name a type; did you mean 'Movement_h'?
   42 |     Movement move; //Movement libary
      |     ^~~~~~~~
      |     Movement_h
*** [.pio\build\teensy40\lib7e2\Movement\Movement.cpp.o] Error 1
In file included from C:\Users\lesee\.platformio\packages\framework-arduinoteensy\cores\teensy4/WProgram.h:46,
                 from C:\Users\lesee\.platformio\packages\framework-arduinoteensy\cores\teensy4/Arduino.h:6,
                 from lib\General\../ILI9341_t3n/ILI9341_t3n.h:101,
                 from lib\General\General.h:7,
                 from lib\General\General.cpp:1:
C:\Users\lesee\.platformio\packages\framework-arduinoteensy\cores\teensy4/wiring.h: In instantiation of 'constexpr decltype (((a < b) ? forward<A>(a) : forward<B>(b))) max(A&&, B&&) [with A = int; B = unsigned int; decltype (((a < b) ? forward<A>(a) : forward<B>(b))) = unsigned int]':
lib\General\General.cpp:133:28:   required from here
C:\Users\lesee\.platformio\packages\framework-arduinoteensy\cores\teensy4/wiring.h:120:12: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
  120 |   return a >= b ? std::forward<A>(a) : std::forward<B>(b);
      |          ~~^~~~
============================================================================================================ [FAILED] Took 7.55 seconds ============================================================================================================

 *  The terminal process "C:\Users\lesee\.platformio\penv\Scripts\platformio.exe 'run', '--environment', 'teensy40'" terminated with exit code: 1. 

(The error within Wire.h doesn’t always pop up only sometimes and it always only throws an error for 1-2 “missing” Headers)

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:teensy40]
platform = teensy
board = teensy40
framework = arduino
lib_deps = 
	Adafruit/Adafruit BNO055 @ 1.6.3
	Adafruit/Adafruit BusIO @ 1.16.1
	Adafruit/Adafruit ILI9341 @ 1.6.1
	Adafruit/Adafruit TSC2007 @ 1.1.2
	hideakitai/TCA9534 @ 0.1.1
	Adafruit/Adafruit NeoPixel @ 1.12.3
	adafruit/Adafruit TCS34725@^1.4.4
	Adafruit/Adafruit_VL6180X @ 1.4.3

I tried including them with relativ paths to the lib_deps folder and tried using “” and <>.

I’ve seen others on this forum have this problem but nothing fixes it.

The whole project would be to large but here are the essential files:
main.cpp

#include <Arduino.h>
#include "../lib/General/General.h"
#include "../lib/Timer/timer.h"
/*
---------------------------------------------------------
----------------------Main-------------------------------
---------------------------------------------------------
*/
int main()
{
   /*
    I cut the main code for this post 'cause it hundreds of lines
   */
   while(true){

   }
}

General.h

#ifndef General_h
#define General_h

//Defines & Enums
#include "DefineEnum.h"
//Display
#include "../ILI9341_t3n/ILI9341_t3n.h"
//Expander
#include "../TCA9534/TCA9534.h"
//Motors
#include "..\Motor\Motor.h"
#include "..\Movement\Movement.h"
//BNO
#include <Adafruit_BNO055.h>
//TOF
#include "../TOF/TOF.h"
//LED
#include "..\Adafruit_Neopixel\Adafruit_Neopixel.h"
//Servo
#include "../Servo/Servo.h"
//Colorsensor
#include "../ColorSensor/ColorSensor.h"
//Camera
#include "../Camera/Camera.h"

class Robot{
    public:
    /*
    I cut everything again
    */
    ~Robot(){ //Destructor of the class
        
    };
    Robot();


    private:

};
#endif

The BusIO libary wasn’t edited and was copied from lib_deps like every other
(Only for some others we changed the include path so they were correct after coping the includes to “lib”)

Don’t do that, if you have a library in lib/ with some exposed header, include only that header name. I think this otherwise confuses the library dependency finder (LDF).

#include <General.h>
#include <timer.h>

Don’t do that, with framework = arduino you need to write an Arduino sketch, which is defined by its

void setup() {
  /* one time init code */
}

void loop() {
  /* executed within while(true) */
}

by defining main(), you overwrite and steal the Arduino core’s main() function, in which import initialization happens, so the firmware is likely non functional for every Arduino function.

Please see documentation

https://docs.platformio.org/en/latest/librarymanager/index.html

With your above platformio.ini, I can build a main.cpp just fine

#include <Adafruit_BNO055.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_TCS34725.h>
#include <Adafruit_TSC2007.h>
#include <Adafruit_VL6180X.h>

void setup() {
    Serial.begin(115200);
}

void loop() {
    Serial.println("test");
}

And, adding a library that references another Arduino library, like General.h, works just fine.

It doesn’t work for me…
I did as you told me:

  • Replaced int main() with void setup() and void loop()
  • Replaced every include path with <HeaderName.h> (for all non official libaries)

And I even deleted all main code and General.h code like I posted and commented every non official libary out like you did but still linking errors (this time it couldn’t find SPI.h 3 times nor Adafruit GFX)

Can you upload the project as a whole to Github or something?

It just worked…
I didn’t include Ili9341 befor but after following the your steps and including it it works!

I’ll look if it’s only because of the not included header or also because of your help (I’ll propably still use void setup(), etc. so I don’t have another problem)

=> If you remove that Adafruit_Ili9341 libary from lib_deps in platformio.ini (and don’t include it) it won’t compile
I have no idea

Correct, because the library dependency finder won’t resolve the dependencies of an unincluded but lib_deps declared library.

I wasn’t really clear with my message, I must say.
I still had to delete almost everything

I als searched for other unincluded libaries but there where none so I deleted the ones we copied into “lib”:
The compiler can’t find the headers (I did change the include from relative paths to ones with <>)

I’ve pushed it to GitHub: GitHub - 8Erigon/maze-BodenseeBeaver
(I need help or I’ll need to copy each libary to “lib” like when I was starting out)

The problem seems to be that VarsfromDogs.h includes General.h and that an instance of the Robot class is created in main.cpp

  1. You have put function definitions and global variable definitions into header files, most prominently in “VarsFromDogs.h”. Global variables must only be declared with extern, global functions must only be declared with their prototype, all the definitions must happen in the .cpp file
  2. You made copies of the libraries you included in lib_deps as well as of core-internal libraries like “Servo” in the lib/ folder
  3. You still used the wrong #include <../LibraryName/LibraryHeader.h> method which confuses the LDF
  4. You create tons of cyclic references which are bad for the C/C++ compiler. E.g., Camera.h includes VarsFromDogs.h includes General.h includes Camera.h. That won’t work at all. You need to break these cyclic references, only strictly includes the types in the header files that you need for declaring a function. The other include can go into the implementation file, aka .c/.cpp file
  5. Use lib_ldf_mode = deep+ to help the library dependency finder identify its dependencies correctly.

Resolving all of these issues produces a compilable firmware.

See

for the fix.

1 Like

Thx to Max Gerhardt for fixing this on GitHub!

  • He fixed a spelling mistake in #include <Adafruit_Neopixel.h> (that’s the correct way)
  • He made every #include a non-relativ path
    (Not #include "../lib/General.h" but #include "General.h"instead)
  • He added a PlatformIO CI file (has something todo with Git)
  • Moved variable&function definitions to a cpp-file and added “extern” in the header to every variable

Additionally he “made the whole mess compiling:laughing: :clap: :+1:

FYI, the “CI” is continous integration, and instructs Github to spin up a Ubuntu machine, install PlatformIO on it and then try to compile the project. If that works, the CI passes and the repo gets the green checkmark. Thus, if you push non-compilable code into the repo, it’s immediately catched and you get a red cross.

grafik

File comes copy-pasted from https://docs.platformio.org/en/latest/integration/ci/github-actions.html.

2 Likes