Logging to monitor in C code

Hi,

In mij ESP32 project I’m using an external library which has a few .c files and I want to debug that code by adding some logging statements, but i cannot seem to add Serial.print statements to the C code. If I include HardwareSerial.h I get a compile error complaining about ` sourcefile not found

How can I do this?

I got it figured out:

  • rename .c to .cpp
  • add this to the top:
#ifdef __cplusplus
extern "C" {
#endif
  • add this to the end
#ifdef __cplusplus
}
#endif

Add #include “HardwareSerial.h” to top of file and you can use Serial.print anywhere

1 Like