创建基于多个组件的esp32静态库



我是esp-idf开发的新手,我想构建一个静态库esp32。我已经阅读了expressif文档(可在这里:编程指南),但我无法创建一个合适的.a文件。

这个想法是开发一个新的包装器和函数库,其中包括来自esp-dsp库的函数。我已经将esp-dsp组件添加到我的项目中,并创建了我自己的组件:my_component

这是我现在的项目结构:

- first_project/
- CMakeLists.txt
- sdkconfig
- components/ - esp-dsp/ - CMakeLists.txt
- ...
- ...
- my_component/ - CMakeLists.txt
- my_component.c
- include/ 
- my_component.h
- main/       - CMakeLists.txt
- main.c
- build/

CMakeLists.txt文件如下:

CMakeLists.txt (first_project)

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

CMakeLists.txt(主要)

idf_component_register(SRCS "main.c"
INCLUDE_DIRS "."
REQUIRES my_component esp-dsp)

CMakeLists.txt (my_component)

idf_component_register(SRCS "my_component.c"
INCLUDE_DIRS "include"
REQUIRES esp-dsp)

my_component.c中有来自esp-dsp的函数

与之前的文件,我设法创建一个二进制flash到ESP32板,但下一步是建立一个静态库(my_library.a),其中有my_component.c内的函数。

所以我试图修改CmakeLists.txt (main),以创建静态库[MyStaticLib。a]关于组件my_component

cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(first_test)
ADD_LIBRARY( MyStaticLib STATIC
components/my_component/my_component.c )
SET( APP_EXE StaticTest )
ADD_EXECUTABLE( ${APP_EXE}
main/main.c ) 
TARGET_LINK_LIBRARIES( ${APP_EXE}
MyStaticLib )

但是,在构建过程中,我看不到my_componentinclude路径文件夹。然后编译失败,因为my_component.h:No such file or directory

FAILED: CMakeFiles/MyStaticLib.dir/components/my_component/my_component.c.obj 
ccache C:Usersjulien.espressiftoolsxtensa-esp32-elfesp-2020r3-8.4.0xtensa-esp32-elfbinxtensa-esp32-elf-gcc.exe   -mlongcalls -Wno-frame-address -g -MD -MT CMakeFiles/MyStaticLib.dir/components/my_component/my_component.c.obj -MF CMakeFilesMyStaticLib.dircomponentsmy_componentmy_component.c.obj.d -o CMakeFiles/MyStaticLib.dir/components/my_component/my_component.c.obj   -c ../components/my_component/my_component.c
../components/my_component/my_component.c:2:10: fatal error: my_component.h: No such file or directory

当我从main修改CMakeLists.txt来构建静态库时,问题才出现。

变量INCLUDE_DIRSCMakeLists.txt文件可以解决这个问题,但无济于事。

是否知道我在CMakeLists.txt参数中做错了,以便构建.a静态库被用作其他项目的组件?

致意。

就像您所做的那样添加组件构建示例。您将看到所有组件在build/esp-idf/文件夹下构建为一个库(.a)。

在其他项目中使用libmy_component.alibesp_dsp.a

最新更新