Bare AVR project can't find library

I’m working on an AVR project that does not use Arduino framework, while also trying to manage libraries using PlatformIO on VSCode but it turns out that I can’t. Honestly I feel a bit surprised that this should be a problem.

So here’s my platformio.ini:

[env:ATmega168P]
platform = atmelavr
board = ATmega168P ; this can be anything; does not matter
lib_deps =
    ; some randomly chosen lib just to show that lib manager is broken
    adafruit/Adafruit MSA301@^1.1.0
    adafruit/Adafruit SleepyDog Library@^1.6.4
    olikraus/U8g2@^2.35.4
    naguissa/uRTCLib@^6.6.1

…then it’s no surprise that .pio/libdeps/ATmega168P contain these libraries. The problem is these libraries are just sitting there doing nothing: they don’t appear in .vscode/c_cpp_properties.json so IntelliSense wouldn’t find any header; and code won’t compile because no headers can be found:

"includePath": [
    "/Users/45gfg9/Documents/PlatformIO/Projects/avrlibtest/include",
    "/Users/45gfg9/Documents/PlatformIO/Projects/avrlibtest/src",
    ""
]

Suppose src/main.cpp is:

#include <avr/io.h>
#include <Adafruit_SleepyDog.h> // IntelliSense yells at this line

int main() {
  return 0;
}

and you get

Compiling .pio/build/ATmega168P/src/main.o
src/main.cpp:2:10: fatal error: Adafruit_SleepyDog.h: No such file or directory

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

 #include <Adafruit_SleepyDog.h>
          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio/build/ATmega168P/src/main.o] Error 1

…and as soon as framework = arduino is specified, the problem goes away. Copying library directories from .pio/libdeps to lib does not work, either.

Here’s another strange thing I’ve observed, but I’m not very sure about this one. It seems that hand-created header and sources can be discovered normally, but ones that are copied from libdeps can’t.

I would bet a signficant amount of these libraries depend on the Arduino framework or a library thereof (SPI, I2C).

The thing that’s probably keeping them from being included is the library dependency check for platform & framework. You can set lib_compat_mode = off in the platformio.ini, but I’m afraid you’ll just get showered with “failed to include Arduino.h” errors.

1 Like

Thank so much! Didn’t know lib_compat_mode before. Guess I’ll have to go over the docs again…

I have an AVR project ( GeoffWebster/PreAmpController (github.com) ) not using the Arduino framework and which includes managed libraries. It works fine. As the previous replies state, your issue probably is due to the libraries you’ve called requiring an Arduino framework.

It for sure is possible and should work, but the project you linked does use Arduino, no? :smiley:

Whoops! You’re absolutely right. I’m confusing myself as I have another project duplicating this one that is purely in native AVR code but the libraries are present in the Library folder within that project, not using the Library manager.

The reason for putting the libraries in the Library folder is purely that I’m using fairly old C libraries produced by Peter Fleury, Filip Sobalski/Guy Carpenter and others that are not present in maintained repositories, e.g. Github.