undefined reference to when linking

greenstone
Posts: 20
Joined: Mon Jul 10, 2023 9:14 am

undefined reference to when linking

Postby greenstone » Tue Sep 03, 2024 2:07 am

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)
Attachments
工程结构.png
project structure
工程结构.png (16.65 KiB) Viewed 1951 times
new2.rar
Wrong project
(71.26 KiB) Downloaded 86 times
new1.rar
Correct project
(75.96 KiB) Downloaded 90 times

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: undefined reference to when linking

Postby MicroController » Tue Sep 03, 2024 2:58 pm

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.

greenstone
Posts: 20
Joined: Mon Jul 10, 2023 9:14 am

Re: undefined reference to when linking

Postby greenstone » Wed Sep 04, 2024 1:07 am

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.

Who is online

Users browsing this forum: No registered users and 155 guests