[Solved] Undefined reference to `Ticker::active()' on ESP32


The Ticker lib is used years for ESP8266, no problems.
For ESP32 the build fails.
Platformio finds the active() function definition and implementation. However, the linking does not pass.

Restart Platformio does not help.
Clean up .pio and .vscode folders does not help.
Rename main.cpp to main.ino does not help.

#include <ESP32Ticker.h>
//#include <Ticker.h>  // Either lib gives the same error.

Ticker touch_outside_timer;

void callbackOutside(){
  if (! touch_outside_timer.active()) {
    touch_outside_ts = millis();
  touch_outside_timer.once(0.1, stopTouchOutside);

Error in build:

Archiving .pio\build\wemosbat\libFrameworkArduino.a
Linking .pio\build\wemosbat\firmware.elf
.pio\build\wemosbat\src\main.cpp.o:(.literal._Z15callbackOutsidev+0x8): undefined reference to `Ticker::active()'
.pio\build\wemosbat\src\main.cpp.o: In function `callbackOutside()':
.../src/main.cpp:137: undefined reference to `Ticker::active()'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\wemosbat\firmware.elf] Error 1

All searches for the topic show that it’s really missing definition or reference.
Please, hint where it could be a problem?
Why liner does not see what Pio sees?

Thank you.

There is no actual implementation of the function as I see.


No Ticker::active() implementation in the entirety of arduino-esp32/Ticker.cpp at master · espressif/arduino-esp32 · GitHub.

This has been known for 2.5 years here, but no commit to resolve it has been merged into mainline.

A suggestion for a fix was however made and you can try to create a fixed library version, e.g. locally in lib/ or pointing to it via lib_deps, that resolves this issue.

Fundamentally, this is a problem of the Arduino-ESP32 core, not PlatformIO.

Thank you @maxgerhardt
Ticker active() method is not defined · Issue #1864 · espressif/arduino-esp32 · GitHub - also here the solution found:

bool Ticker::active(){ return (bool)_timer; }

Adding this line into Ticker.cpp solves the problem.

Answering “Why linker does not see what Pio sees?”
C++ Linker observes correct local horizon of code in the given project.
While Pio is “too smart” and brings you whatever it can find. In this particular case Pio jumped to Ticker of ESP8266 which is implemented properly.