Page 1 of 1

Creation of custom component - "undefined reference" error

Posted: Mon Jun 17, 2019 12:24 pm
by joelguittet
Hello all !

I'm new to the forum and already browse it, found similar issues but didn't succeed to find a solution in my case...
I'm using an ESP-32 and try to make a custom component. I'm not able to build it, I have a linker error... here is my project tree:

project
--components
----test
------include
--------test.h
------component.mk
------test.c
--main
----CMakeLists.txt
----component.mk
----main.c
--CMakeLists.txt
--Makefile

The content of the file is the following (not all the file, only the main one regarding to this issue):

project\components\test\include\test.h

Code: Select all

void test_function(void);
project\components\test\component.mk

Code: Select all

# Empty
project\components\test\test.c

Code: Select all

void test_function(void) { /* Some stuff */ }
project\main\CMakeLists.txt

Code: Select all

set(COMPONENT_SRCS "main.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
register_component()
project\main\component.mk

Code: Select all

# Empty
project\CMakeLists.txt

Code: Select all

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

Code: Select all

PROJECT_NAME := project
include $(IDF_PATH)/make/project.mk
My application access to the "test_function" of the new component "test".
When building I have error "undefined reference to `test_function`" :-(
If I define the "test_function" in the "test.h" file, this is working.
I have already checked logs with "make V=1", the library is included in the building of my application "-ltest", and it exists.

I don't know where my setup is wrong.
If anyone can point something which is not good, I will try to do it, at this moment I have no more idea after several hours of testing and searching for custom component tutorial !

Thanks to all,
Joel

Re: Creation of custom component - "undefined reference" error

Posted: Mon Jun 17, 2019 1:10 pm
by joelguittet
Found the error myself, it was due to a typo in test.c file :roll: :lol:
The above tree tutorial can be used to create a new component, if people are searching for that, this is working!
Joel