How to solve undefined reference when using text_sensor template?

I have a esphome esp32 project with the following code:

text_sensor:
  - platform: template
    name: "Upload Time"
    update_interval: never
    lambda: |-
      return {"Hello world"};

results in:

Linking .pioenvs/podlogowe/firmware.elf
/home/kamil/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: .pioenvs/podlogowe/src/main.cpp.o:(.literal._Z5setupv+0x178): undefined reference to `_ZTVN7esphome9template_18TemplateTextSensorE'
/home/kamil/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: .pioenvs/podlogowe/src/main.cpp.o:(.literal._Z5setupv+0x17c): undefined reference to `_ZTVN7esphome9template_18TemplateTextSensorE'
/home/kamil/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: .pioenvs/podlogowe/src/main.cpp.o:(.literal._Z5setupv+0x32c): undefined reference to `_ZN7esphome9template_18TemplateTextSensor12set_templateEOSt8functionIFNS_8optionalINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEvEE'
/home/kamil/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: .pioenvs/podlogowe/src/main.cpp.o: in function `_Z5setupv':
/home/kamil/myprojects/dabrowskiej/esphome/.esphome/build/podlogowe/src/main.cpp:608:(.text._Z5setupv+0xb60): undefined reference to `_ZN7esphome9template_18TemplateTextSensor12set_templateEOSt8functionIFNS_8optionalINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEvEE'
/home/kamil/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: .pioenvs/podlogowe/src/esphome/core/controller.cpp.o:(.literal._ZN7esphome10Controller16setup_controllerEb+0x28): undefined reference to `_ZN7esphome11text_sensor10TextSensor21add_on_state_callbackESt8functionIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE'
/home/kamil/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: .pioenvs/podlogowe/src/esphome/core/controller.cpp.o: in function `_ZN7esphome10Controller16setup_controllerEb':
/home/kamil/.platformio/packages/toolchain-xtensa-esp-elf/xtensa-esp-elf/include/c++/14.2.0/bits/std_function.h:452:(.text._ZN7esphome10Controller16setup_controllerEb+0x132): undefined reference to `_ZN7esphome11text_sensor10TextSensor21add_on_state_callbackESt8functionIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE'

I do not undersatnd why there are any linking errors? Please kindly help me debug and solve. Thank you.

Looks like something is broken. What esphome version you have?

1 Like

Hello @karosm I have esphome-2025.10.5-1 installed on archlinux. I still work on an reproducible example, should have one soon.

The first steps I would be doing is updating both Home Assistant and ESPHome to the latest stable releases, cleaning the build files, and trying again.

No harm in trying just the latter first if you prefer.

1 Like

Hello. All fixed after changing arduino to esp-idf. Might be some incompatibility or something. No idea why I had arduino. Thank you much for assist.