How to fix Arduino / PlatformIO undefined reference to `loop()'
Problem:
While trying to compile your Arduino or PlatformIO project, you see an error message such as
linker_error_ld.txt
/home/uli/.platformio/packages/[email protected]+2021r2-patch5/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32dev/libFrameworkArduino.a(main.cpp.o):(.literal._Z8loopTaskPv+0x8): undefined reference to `loop()'Solution
You have not declared a loop() function in your source code. Open main.cpp or your .ino source code file and start with the following (empty) loop() function which does nothing:
empty_loop_example.cpp
void loop() {
// Nothing to do here since HTTPServer
// is running in a separate thread
delay(1000);
}After you’ve added any void loop() { /* ... */} function to your sourcecode try to build/upload again and the error message should have disappeared.
If you want, you can also add code such as to print a message to the serial port every time the loop is run:
loop_with_serial_example.cpp
void loop() {
// Nothing to do here since HTTPServer
// is running in a separate thread
Serial.println("Hello world!");
delay(1000);
}Check out similar posts by category:
Arduino, C/C++, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow