How to link Eigen to C++ code when using PlatformIO

I have a PlatformIO project, which its main directory has the following structure:

.pio/
lib/
|— Eigen/
|— code.h
|— code.cpp
src/
|— main.ino
platformio.ini

code.h has dependency on Eigen/Dense, and if I try to compile an application, let’s name it app.cpp, which uses code.h, I face no issues and I am able to compile it and run it. However, when I include code.h into main.ino, and execute ‘pio run’ in the terminal, I get several compiling errors coming from Eigen files (I am using Eigen 3.4.0).

I have tried what is suggested here but it did not work

Anyone who has any idea of what might be the issue of trying to include eigen dependent code into .ino files OR how to properly link them when using PlatformIO?

If anyone want to see the prompt output and errors:

I have tried also what is suggested here, which is loosely what is done in ArduinoEigen, which I also tried to use. From the reply above, you can see the error comes from conflicting macros between esp32 lib and Eigen.

In your main.cpp, do you first include the Eigen lib and then Arduino.h? With the .ino, “include Arduino.h first” is forced and might mess up the program.

1 Like

I don’t have a main.cpp, but following your reason I included the code dependent on Eigen or Eigen itself before including arduino.h, and still gives me the same error :confused: