Page 1 of 1

undefined reference to when linking

Posted: Tue Sep 03, 2024 2:07 am
by greenstone
Hello everyone, the main component calls a function in component A(wifi_app), and component A calls a function in component B(port_event). Component A has added a dependency on component B to its CMakeLists, but when linking, the function defined in component B cannot be found, prompting an "undefined reference to 'port_clear/get/set_status (EVENT, GROUP, SELECT_T, unsigned long)'. I changed this statement to xEventGroupClearBits/xEventGroupSetBits/xEventGroupWaitBits , There are no issues with compiling and linking. May I ask where the problem lies? Seeking guidance.

Projects with successfully compiled links, such as new1, and projects with problematic compiled links, such as new2
I have compiled on both Ubuntu and Windows environments, and the ESP-IDF versions are 5.1.0 and 5.3.0 respectively (currently not affected), both of which report the same error.

The CakeLists for custom component A (wifi_app) are as follows:

idf_component_register(SRCS "wifi_device.cpp"
INCLUDE_DIRS ". "
REQUIRES freertos esp_system esp_wifi esp_event esp_ringbuf
main_config
port_debug
port_event
hal_param_manage
)

The CakeLists for custom component B (port_event) are as follows:
idf_component_register(SRCS "port_event.c"
INCLUDE_DIRS ". "
REQUIRES freertos esp_system log
)

The CakeLists for component mian are as follows:
idf_component_register(SRCS "user_main.c"
INCLUDE_DIRS ""
REQUIRES)

Re: undefined reference to when linking

Posted: Tue Sep 03, 2024 2:58 pm
by MicroController
greenstone wrote:
Tue Sep 03, 2024 2:07 am
Component A has added a dependency on component B to its CMakeLists, but when linking, the function defined in component B cannot be found, prompting an "undefined reference to 'port_clear/get/set_status (EVENT, GROUP, SELECT_T, unsigned long)'.
If the main component needs to access functions from the "port_event" component, like port_event_init(), the main component should declare a dependency on "port_event" too.

Re: undefined reference to when linking

Posted: Wed Sep 04, 2024 1:07 am
by greenstone
Thank you for your reply. I will give it a try, but the tutorial video I saw did not require this. Instead, it stated that 'main' is a special component that includes default components from the installation directory and custom components from the project directory.