如何在ESP-IDF项目中添加外部库

发布于 2025-02-05 17:24:41 字数 1631 浏览 3 评论 0原文

我一直在尝试修复几天,因此任何洞察力都将不胜感激。我正在使用ESP32板和VSCODE的ESP-IDF框架来构建一个项目。我很难访问外部库的功能。例如,我已经在C中实现了一个FFT-Noise滤波器程序,现在我想将其带入ESP-IDF框架中。我认为这与我对Cmake的不熟悉有关,我尝试了各种不同的“ cmakelists.txt”,但不确定它应该是什么样的。我经历了CMAKE教程,但我无法弄清楚。这是我当前的“ cmakelists”内部文件夹中的“ cmakelists”,

idf_component_register(SRCS "hello_world_main.c"
                    INCLUDE_DIRS ".")

我从ESP-IDF的示例中取了一个示例项目“ hello_world”,然后在“ hello_world_main.c”中写下了我自己的代码。这很奇怪,因为在我的“ hello_world_main.c”中,Crumplier似乎知道一些数据类型,例如'fftw_complex',这些数据仅在我要使用的库中找到。但是,当我从同一库中调用诸如fftw的“ malloc”之类的任何函数时,我会

从hello__world_main.c的'app_main()中摘录

//complex: double[2] = {real_part,imag_part} 
fftw_complex *in, *out;  //no errors here for some reason
fftw_plan p;

//initialize the arrays-> "in" is an array of fftw_complex type (basically a pair of doubles)
//in is f (set of points we know) -> out is fhat (complex fourier coefficents) with magnitude and phase
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); //'undefined reference to fftw_malloc'
Error message:

到fftw_malloc()的fftw_malloc()''norde trece to reffftw_malloc():[5/7] 失败:hello_world_2.elf cmd.exe /c“ cd。 -elf-g ++ -mlongcalls -wno -frame -address @cmakefiles \ hello_world_2.feld_2.fel.rsp -o hello_world_2.elf&&&&光盘 。” c:/users/bgreenwood/.espressif/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-eptensa-esp32-elbin/../ lib/gcc/ lib/gcc/ xtensa-estensa-esp32-fell/8.4 .0 /../../../../../ XTENSA-EST32-ELF/BIN/LD.EXE:ESP-IDF/MAIN/LIBMAIN.A(HELLO_WORLD_MAIN.C.OBJ) 0x1c):未定义的引用 ``fftw_malloc''

所以我的问题是,我如何才能获得我的主机来识别我正在拨打的功能?

I've been trying to fix this for a couple days so any insight would be greatly appreciated. I am building a project with an ESP32 board and VSCode's esp-idf framework. I am having trouble getting access to an outside library's functions. For example, I have implemented an FFT-noise-filter program in c, and now i want to bring it into the esp-idf framework. I think it has something to do with my unfamiliarity with CMake, and I have tried all sorts of different "CMakeLists.txt", but not sure what it should look like. I've been through cmake tutorials, but I just can't figure it out. Here's my current 'CMakeLists' inside main folder

idf_component_register(SRCS "hello_world_main.c"
                    INCLUDE_DIRS ".")

I took an example project 'hello_world' from esp-idf's examples, and wrote my own code inside of the 'hello_world_main.c'. It is weird because in my "hello_world_main.c" the complier seems to know some data types such as 'FFTW_Complex', which are only found in the library I'm trying to use. However, when I call any functions like FFTW's 'malloc' from that same library, I get an error "undefined reference to fftw_malloc()"

excerpt from hello_world_main.c's 'app_main():

//complex: double[2] = {real_part,imag_part} 
fftw_complex *in, *out;  //no errors here for some reason
fftw_plan p;

//initialize the arrays-> "in" is an array of fftw_complex type (basically a pair of doubles)
//in is f (set of points we know) -> out is fhat (complex fourier coefficents) with magnitude and phase
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); //'undefined reference to fftw_malloc'
Error message:

[5/7] Linking CXX executable hello_world_2.elf
FAILED: hello_world_2.elf
cmd.exe /C "cd . && C:\Users\bgreenwood.espressif\tools\xtensa-esp32-elf\esp-2021r2-patch3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe
-mlongcalls -Wno-frame-address @CMakeFiles\hello_world_2.elf.rsp -o hello_world_2.elf && cd ."
c:/users/bgreenwood/.espressif/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(hello_world_main.c.obj):(.literal.app_main+0x1c): undefined reference to
`fftw_malloc'

so my question is, how can I get my main to recognize the function calls I am making?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自找没趣 2025-02-12 17:24:41

将您的libcode.c添加到:

idf_component_register(SRCS "hello_world_main.c" “libcode.c”
INCLUDE_DIRS ".")

并将引用添加到libcode.h:

#include “libcode.h”

libcode是一个人造名称,通过正确的名称更改它,您也可以在需要时添加一个目录,例如“ libcode/libcode.h”,

希望这可以回答您的问题;使用更多代码,更容易理解您的问题。

Add your libcode.c to:

idf_component_register(SRCS "hello_world_main.c" “libcode.c”
INCLUDE_DIRS ".")

And add a reference to libcode.h:

#include “libcode.h”

Libcode is an artificial name, change it by the correct one and you could also add a directory if needed like “libcode/libcode.h”

Hope this answers your question; with more code it’s easier to understand your problem.

走走停停 2025-02-12 17:24:41

要检查最小组件的外观,您可以使用idf.py create-component name创建一个。将制作名称名称的组件,您可以检查外部库中缺少的内容。

To check what the minimal component would look like, you can create one using idf.py create-component NAME. The component named NAME will be made, and you can check what is missing in your external library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文