madhephaestus / ESP32Servo

Arduino-compatible servo library for the ESP32
132 stars 52 forks source link

Using Library with ESP-IDF and arduino #60

Open MarleyPlant opened 1 month ago

MarleyPlant commented 1 month ago

I have an ESP-IDF project for the ESP32-c6, I have the arduino-esp32 component added through the component registry and then have placed ESP32Servo in components folder with the following CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
idf_component_register(SRCS "src/ESP32PWM.h" "src/ESP32Servo.h"
                    INCLUDE_DIRS "src/."
                    REQUIRES "arduino-esp32" # Library requires Arduino
                    )

project(ESP32Servo)

my main CMakeLists.txt file is as follows

set(COMPONENT_REQUIRES "WebSockets")
set(COMPONENT_REQUIRES "THERMISTOR")
set(COMPONENT_REQUIRES "ESP32Servo")

idf_component_register(
    SRCS "main.cpp"
    INCLUDE_DIRS ""
)

when trying to build the project I get the following error.

components/ESP32Servo/src/ESP32Servo.h:129: undefined reference to `ESP32PWM::~ESP32PWM()'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

any ideas what I am doing wrong?

madhephaestus commented 1 month ago

The destructor is explicitly defined in https://github.com/madhephaestus/ESP32Servo/blob/ec5a4cefc29f9643c9175d4146a5f47e11ec9496/src/ESP32PWM.cpp#L51

Maybe look at SRCS "src/ESP32PWM.h" "src/ESP32Servo.h" INCLUDE_DIRS "src/." It looks like you set the src dir as the search dir, then say the headers are relative path of src/... I think this would result in it looking for the headers in src/src/ESP32Servo.h