【发布时间】:2022-06-11 18:41:26
【问题描述】:
几天来我一直在尝试解决此问题,因此我们将不胜感激任何见解。我正在使用 ESP32 板和 VSCode 的 esp-idf 框架构建一个项目。我无法访问外部库的功能。例如,我在 c 中实现了一个 FFT-noise-filter 程序,现在我想将它带入 esp-idf 框架。我认为这与我对 CMake 的不熟悉有关,我尝试了各种不同的“CMakeLists.txt”,但不确定它应该是什么样子。我已经通过 cmake 教程,但我就是想不通。这是我当前在主文件夹中的“CMakeLists”
idf_component_register(SRCS "hello_world_main.c"
INCLUDE_DIRS ".")
我从 esp-idf 的示例中提取了一个示例项目“hello_world”,并在“hello_world_main.c”中编写了自己的代码。这很奇怪,因为在我的“hello_world_main.c”中,编译器似乎知道一些数据类型,例如“FFTW_Complex”,这些数据类型只能在我尝试使用的库中找到。但是,当我从同一个库中调用 FFTW 的 'malloc' 之类的任何函数时,会出现错误“对 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:
[5/7] 链接 CXX 可执行文件 hello_world_2.elf 失败: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): 未定义的引用 `fftw_malloc'
所以我的问题是,我怎样才能让我的 main 识别我正在进行的函数调用?
【问题讨论】:
标签: visual-studio-code cmake undefined-reference esp-idf