esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
293 stars 36 forks source link

Sperate header & cpp files for custom components #3803

Closed dtila closed 2 years ago

dtila commented 2 years ago

The problem

The build is ok but the linker give me the error:

/config/plantwatering.yaml:12: undefined reference toPlantDiscovery::PlantDiscovery()'`

All the documentation for a custom component is the code is in the header file. Can you have code in header and cpp file, when you build a custom component for esphome?

In case, how you specify the cpp files to be linked?

Which version of ESPHome has the issue?

docker version - latest

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP8266

Board

No response

Component causing the issue

No response

Example YAML snippet

esphome:
  name: plantwatering
  includes:
    - plantDiscovery.h
    - plant.h

sensor:

custom_component:
  - lambda: |-
      auto plant = new PlantDiscovery();
      return {plant};
    components:
    - id: plants

Anything in the logs that might be useful for us?

No response

Additional information

No response

dtila commented 2 years ago

Fixed. Information found in the documentation

hcoohb commented 1 year ago

Hi @dtila , I am having the same issue, would you be able to point me to the part of the documentation describing how to fix this? Thanks

ssieb commented 1 year ago

You have to include the .cpp file as well. But if you have any further questions, ask on the discord server or one of the forums.