Page 1 of 1

undefined reference

Posted: Mon Mar 30, 2020 8:24 pm
by su-Koch
Hei Guys,
I'm a beginner in cmake as I'm working with Visual Studio normally.
I'm trying to set up a project with two components, one inherits from the other.

The Structure of the Tree is attached.
The issue is that I get an error "undefined reference" for the Component I want to inherit from.

CMakeLists.txt are:
I2CKeypad:
idf_component_register(SRCS "I2CKeypad.cpp" INCLUDE_DIRS "." "../I2CPeripheral")

I2CPeripheral:
idf_component_register(SRCS "I2CPeripheral.cpp" INCLUDE_DIRS ".")

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

project:
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(i2cKeypad)

I2CPeripheral.h is includes in I2CKeypad.h

Hopefully there is a person out there that knows how to solve this.
Please let me know if you need more information.
Thanks.

Re: undefined reference

Posted: Thu Apr 02, 2020 2:26 am
by ESP_renz
You need to populate the REQUIRES, PRIV_REQUIRES argument to idf_component_register with the proper dependency relationships.

For example, you mentioned that I2CKeypad depends on I2CPeripheral for I2CPeripheral.h, I2CKeypad should be:

Code: Select all

idf_component_register(SRCS "I2CKeypad.cpp" INCLUDE_DIRS "." REQUIRES I2CPeripheral)

Notice I also removed the "../I2CPeripheral". Establishing this dependency between I2CKeypad and I2CPeripheral should automatically propagate I2CPeripheral's public include directories (INCLUDE_DIR argument) to other component that REQUIREs it.

Re: undefined reference

Posted: Fri Apr 03, 2020 11:48 am
by su-Koch
What I did now:

Changed
CMakeLists.txt of I2CKeypad:
idf_component_register(SRCS "I2CKeypad.cpp" INCLUDE_DIRS "." "../I2CPeripheral")

to
idf_component_register(SRCS "I2CKeypad.cpp" INCLUDE_DIRS "." REQUIRES I2CPeripheral)

but the error is still there.

Re: undefined reference

Posted: Tue Apr 07, 2020 3:02 am
by ESP_renz
Can you post the build log?