Exclude specific libraries from building


I’m working on a project where two different target environments use two different libraries, in this case one target needs Adafruit_ILI9341 (for wemos_d1) and the other needs ILI9341_t3 (for teensy31) and these are specified in my platformio.ini file.

Unfortunately, when I build for the demos_d1 environment, the teensy library tries to build but fails.

How can I express that specific libraries should only be built for specific environments?


You need lib_deps + lib_ignore depending on a situation.
See Library Dependency Finder (LDF) — PlatformIO v6.1 documentation

Ah, lib_ignore, I totally missed that. Thanks, Ivan!

Sorry, I’m missing something.

When I use lib_ignore it does successfully ignore the specified libraries and doesn’t install them in .piolibdeps


If I build another environment that uses the ignored library and then try to build again, it fails as it tries to build the ignored library.

Hm… Could you share platformio.ini?

Sure thing:

env_default = teensy31

libs =
  SparkFun APDS9960 RGB and Gesture Sensor

teensylibs =

esplibs =
  Adafruit GFX Library

platform = teensy
framework = arduino
board = teensy31
board_f_cpu = 96000000
lib_deps = ${common.libs} ${common.teensylibs}
lib_ignore = ${common.esplibs}

platform = teensy
framework = arduino
board = teensy36
board_f_cpu = 120000000
lib_deps = ${common.libs} ${common.teensylibs}
lib_ignore = ${common.esplibs}

platform = espressif8266
framework = arduino
board = d1_mini
lib_deps = ${common.libs} ${common.esplibs}
lib_ignore = ${common.teensylibs}

Wow! Excellent using of dynamic variables and project dependencies. Looks, that our efforts for PlatformIO 3.0 have a big benefit.

Please check docs Redirecting...

The correct value for this option is library name (not folder name).

The “Links2004/Adafruit_ILI9341” is not a library name. Check pio lib list for the names.

Thanks, I see. That fixed it.

It does seem strange that libraries can be installed with a broader syntax than they can be ignored. This seems to have the side effect that when you want to use two libraries that have the same name (for example, two different forks or git revisions) in two different environments, that means that they get reinstalled each time you switch.

It also means that I need to refer to a given library using two different syntaxes in the .ini file, but that’s not a huge deal.

BTW: PlatformIO 3.0 is awesome and you are my hero, Ivan. Keep up the great work!

I didn’t find a better solution. All package managers work with the ONE registry. PlatformIO allows using multiple ways how to install a library. What is more, a user can put library manually to one of Library Storages. We propose to use external extra library storages. See Library Dependency Finder (LDF) — PlatformIO v6.1 documentation

The only one thing that is common between these libraries is NAME. We support 3-rd party manifests, Arduino.properties, ARM mbed module.json and etc.

In this case, “Installation” process live on the one planet, where the Library Dependency Finder lives in another.

Thanks!!! I can’t wait when PIO Remote will be announced. It’s amazing with unique features in the market!!!

Darn. I was hoping that if I used the link to a github archive zip in lib_deps that if I then used the whole identical URL in lib_ignore it would be ignored.

So, for now I can just add the library as a lib_deps entry in all the targets that can build it, and leave it out of those that can’t.

Ahhhh. Nevermind. I delved into the mysteries of .piolibdeps and discovered that if I use the commit-id of the archive, I can use it in lib_ignore too. That will work!

The only reason I’m going to all this trouble is so those who build our project on Windows don’t get a complaint about the lack of git. For some reason they get annoyed with us.

You can ignore libraries by their names. You should see their names in dependency graph

I wanted to eliminate the dependency on git to build our project, so I changed all lib_deps to use the link to the .zip archives instead, which use the name of the branch (master) as the filename. For example:

lib_deps https : // github . com/trinamic/TMC26XStepper/archive/master.zip

(URLs split up to allow more “links in post” for my n00bness)

When this form is used the line lib_ignore TMC26XStepper fails to prevent this library from being compiled.

During my troubleshooting I noticed in the case of one library the subfolder created inside .piolibdeps was named master with no hash added. I discovered if I used lib_ignore master then that specific library would be ignored.

It was then I realized I could use the commit hashes instead. For example…

https : // github . com/lincomatic/LiquidTWI2/archive/30aa480.zip
https : // github . com/ameyer/Arduino-L6470/archive/3cd0993.zip
https : // github . com/trinamic/TMC26XStepper/archive/c1921b4.zip

And then lib_ignore c1921b4 works! It prevents TMC26XStepper from being compiled.

I don’t know why lib_ignore TMC26XStepper fails to prevent the library from being compiled, but it does. We couldn’t get our Travis CI to pass whatsoever until I went through the process I just outlined.

I can only assume that when PlatformIO sees a link to a .zip file, it doesn’t take the extra notice that it’s a Github archive link and pick out the TMC26XStepper segment of the path as the ID of the library.

Was this ever a known issue? I believe I already patched up our .travis.yml file to use the latest version of PlatformIO. Also, I had the same problem within Visual Studio Code using 3.5.2b2.

See example here

Also, please take a look at <name> at Redirecting...

P.S: Have you tried lib_ldf_mode = chain+?

is there a way to exclude files from within a library tree?
and is it possible to compile .c files as .cpp?


Yes, you need library.json and build.srcfilter field.