Adding main.cpp in local lib, halts Arduino code


I have 2 projects locally: a library and a avr that targets an Arduino Uno.

The library has the library.json file and everything is discovered correctly. On the AVR side I have included using

lib_extra_dirs = ../core

However, when I include a line in the main file, the program does not run on the Arduino board (in my case the LED does not blink anymore).

#include <logging/logging.h> // <-- problematic include line
the logging.h file is in the core project

I suspect it is something with the build itself since everything uploads and I don’t see any warning.

I have created a sample project that reproduces the issue:

I have read all the documentation and I don’t see what I am missing. I suspect this is a bug.

Well if the library’s src/ code has

then halting the core is extremely sure, you are overwriting the main() function defined in the Arduino core…

1 Like

No way! I have added a more complex condition and now works, thank you!!! I can not tell hoe many hours I lost with this …

So the reason I have the main is that I want to build the source (Build task executes successfully, but also be able to debug unit tests.

Is there any better way?

Put the src/main.cpp outside of src/ so that it’s not built by default when the folder is included as a library, then readded when you want to treat your project like a PlatformIO project by adding a src_filter expression that adds back the file (src_filter = +<opt_src/main.cpp>) to the platformio.ini.

1 Like