【发布时间】:2021-09-23 16:12:31
【问题描述】:
我是 esp-idf 开发的新手,我想为 esp32 构建一个静态库。 我已阅读 espressif 文档(可在此处获得:Programming Guide),但无法创建正确的 .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的函数
使用之前的文件,我设法创建了一个二进制文件以闪存到 ESP32 板上,但下一步是构建一个静态库 (my_library.a),其中包含 my_component.c 中的函数。
所以我尝试修改CmakeLists.txt (main)以创建关于组件my_component的静态库[MyStaticLib.a]
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_component 的include 路径文件夹。然后编译失败是因为my_component.h:No such file or directory
FAILED: CMakeFiles/MyStaticLib.dir/components/my_component/my_component.c.obj
ccache C:\Users\julien\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-gcc.exe -mlongcalls -Wno-frame-address -g -MD -MT CMakeFiles/MyStaticLib.dir/components/my_component/my_component.c.obj -MF CMakeFiles\MyStaticLib.dir\components\my_component\my_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 以构建静态库时才会出现问题。
我虽然 CMakeLists.txt 文件中的变量 INCLUDE_DIRS 可以解决问题,但徒劳无功。
知道我在 CMakeLists.txt 参数中做错了什么以便构建 .a 静态库以用作其他项目中的组件吗?
问候。
【问题讨论】:
标签: components static-libraries esp32 esp-idf