Build attempts to compile all files in library, not just those included, or fails to find anything

Hi, I’m new to PlatformIO and really struggling with including libraries that are not part of the Arduino/PlatformIO ecosystem.

I am writing an embedded project and want to use libeigen (libeigen / eigen · GitLab). No matter how I try to include this in my project, when I attempt to build I get hundreds of errors linked to the benchmarks and examples included in the Eigen repo (despite the fact that at no point in my code do I include these), or I simply can’t build it at all.

I have tried:

  1. Cloning the repo to my shared libs dir and adding this with lib_extra_dirs = /Users/mariana/PlatformIO/Shared/
  2. Cloning the repo into the project’s /lib dir, (which I want to avoid as I want to use it for multiple different projects and not duplicate it each time)
  3. Adding the repo’s URL using lib_deps = git+https://gitlab.com/libeigen/eigen.git
  4. As with #3 but without the git+ preposition

Even with the most basic main.cpp file that just has:

#include <Arduino.h>
#include <Eigen/Dense>
void setup() { }
void loop() { }

I cannot get the library to work.

In the case of #1 and #2 I get hundreds of errors like:

/Users/mariana/PlatformIO/Shared/eigen/bench/BenchUtil.h:11:57: fatal error: boost/preprocessor/repetition/enum_params.hpp: No such file or directory
/Users/mariana/PlatformIO/Shared/eigen/bench/BenchUtil.h:11:57: fatal error: boost/preprocessor/repetition/enum_params.hpp: No such file or directory

I have not referenced or included the benchmarks anywhere. If I delete the /bench/ dir I instead get errors thrown by example projects in the repo, which I also haven’t included.

In the case of #3 I get red lines under the Eigen includes in main.cpp and immediate compile failure because it cannot find them. But if I type:

pio lib install git+https://gitlab.com/libeigen/eigen.git

In the CLI I get:

Library Manager: eigen @ 0.0.0+20210217162937.sha.be0574e is already installed

And curiously when I check what is downloaded, it is nothing like what the repo itself contains, instead mostly containing files relating to the performance monitoring / benchmarking and none of the actual Eigen files:

What am I doing wrong here? My ideal solution would be to have a separate directory in my filesystem where I keep my shared files, linked to their respective repos, then included these from PIO. However it seems no matter what I do I can’t get this library to be included correctly.

Many thanks

I just noticed there is a fork of libeigen here: https://github.com/mcprakash/Eigen

Which correctly downloads and the minimal main.cpp I posted above compiles. But I am still very confused as to why when including the main libeigen repo (libeigen / eigen · GitLab) PlatformIO attempts to compile files that are never referenced, such as the benchmarks and examples.

As the rest of my team are using main libeigen repo for desktop simulations so for embedded I want to get this running on our hardware if possible.

The linked repository has no library.json (or Arduino-style library.properties) file that tells PlatformIO how the library should be compiled. In such a case PlatformIO will generically attempt to compile all source files in the library folder – for a complex project such as Eigen with a dedicated CMakeLists.txt / CMake build system with conditionally compiled files and seperated benchmarks or tests source files, this will of course fail horribly.

This fork has made the library Arduino-compatible by foremost just including the actually to-be-compiled files in the src/ folder while ignoring all other files. In that case the library.json file doesn’t play a huge rule because it doesn’t contain build instructions (srcFilter or anything, see link), the projcet is buildable purely because it only contains the files which are meant to be built for the library (no test / benchmarks).

So if you want to use the latest libEigen version from the repo, you need to either do as the forked repo does (fish out the actual library files and put them in the src/ folder of a library folder, plus metainfo) or create a library.json that builds libEigen successfully (by using source filters and build flags for include folder etc.) Examples for such a file is linked in the repo (or here is also one). Then you can fork libEigen and add your library.json file. If libEigen updates, you need to merge back changes (with git and upstream branches pretty easy).

Hi Max,

Thanks for the fast and thorough reply, I was very confused why it was trying to build everything especially when VSCode had seemingly detected CMakeLists.txt and installed an extension for it.

I’ll try forking locally and modifying as you suggest.

Mariana

VSCode auto-suggests the CMake extension when a CMake file is opened purely based on the file extension, but this is separate from PlatformIO. The CMake extension doesn’t interact with the PlatformIO extension in any way constructively – if anything, they might try to get into each others way if they’re trying to define VSCode configuration files in .vscode/ at the same time. In general, PlatformIO can’t process CMake build instructions since it’s built on SCons (Python) and has it’s own library.json meta-format for build information for a library. The only special exception is the ESP32 + ESP-IDF combination where PlatformIO has coded a special wrapper to actually use the CMake files. This doesn’t work anywhere else though so if you’re not using exactly that, it doesn’t apply.

Also the CMake extension has been reported to conflict with the PlatformIO extension in some cases related to debugging tasks (Supporting PlatformIO and non PlatformIO development on same system/), so if they are problems or CMake isn’t actually used, that extension should be removed.