I’m implementing my own assert() macro, for Arduino UNO.
It works ok when I put the files assert.cpp/.h into a dedicated lib/ subdirectory, but does not work if I put those same files in src/ and include/ dirs respectively. Why is that?
FAILS (gets stuck without printing the assert message)
However I don’t see how this is modifyable if it needs to be modified. If the macro __ASSERT_USE_STDERR is set, it will attempt to call into fprintf() to print the error message. Additional syscall implementation has to be made to redirect that to Serial, see here and here for redirecting stdout and stderr.
This is expected. Files in the include/ folder of the project are by default not seen within libraries. Thus when your library does #include <assert.h> it gets avr-libc’s version of assert(), which, since I don’t see __ASSERT_USE_STDERR being defined, does a call to abort() if the assertion fails, hanging up. You can use build_flags to expose the include folder to all libraries, e.g. with build_flags = -Iinclude/ in the platformio.ini.
Correct, since now assert.h is seen as coming from that library, and libraries can see other libraries and their include files just fine.
However I suggest you not name your assert also assert.h as there is ambiguity then.