Wrap around ESP function
Posted: Thu Oct 10, 2024 7:28 am
Hello everyone.
I want to build a wrapper around some ESP function. Inside the function wrapper, I will execute my own code and call the original function. For example i want to wrap esp_panic_handler function.
Inside the main CMakeLists.txt I have the following commands:
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(application_name "PROJECT")
project(${application_name})
target_link_libraries(${project_elf} PRIVATE "-Wl,--wrap=esp_panic_handler")
Inside the project, for example in the folder MyPanic.c, I have a function defined
The compilation result is:
system.a(panic_handler.c.obj): in function `panic_handler':
C:/Espressif/frameworks/esp-idf-v5.0/components/esp_system/port/panic_handler.c:189: undefined reference to `__wrap_esp_panic_handler'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
How to solve the problem, so that the linker "sees" the Wrap.. function.
Tny
I want to build a wrapper around some ESP function. Inside the function wrapper, I will execute my own code and call the original function. For example i want to wrap esp_panic_handler function.
Inside the main CMakeLists.txt I have the following commands:
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(application_name "PROJECT")
project(${application_name})
target_link_libraries(${project_elf} PRIVATE "-Wl,--wrap=esp_panic_handler")
Inside the project, for example in the folder MyPanic.c, I have a function defined
Code: Select all
void __real_esp_panic_handler(panic_info_t *info);
void __wrap_esp_panic_handler(panic_info_t *info)
{
// My code ...
__real_esp_panic_handler(info);
}
system.a(panic_handler.c.obj): in function `panic_handler':
C:/Espressif/frameworks/esp-idf-v5.0/components/esp_system/port/panic_handler.c:189: undefined reference to `__wrap_esp_panic_handler'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
How to solve the problem, so that the linker "sees" the Wrap.. function.
Tny