【问题标题】:How to add an outside library to an ESP-IDF Project如何将外部库添加到 ESP-IDF 项目
【发布时间】: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


    【解决方案1】:

    将您的 libcode.c 添加到:

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

    并添加对 libcode.h 的引用:

    #include “libcode.h”
    

    Libcode 是一个人为的名字,改成正确的名字,如果需要你也可以添加一个目录,比如“libcode/libcode.h”

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

    【讨论】:

    • 我把我的项目放在了我的github上github.com/ben-jammin24/SO_Q我之前尝试过,我很抱歉没有提供足够的上下文感谢您的回复@RemyHx。我的库是这里预编译的 windows x64 版本fftw.org/install/windows.html
    • 你好不知道这个库,但是不是Fortran版本的,你需要.C版本吗?
    • 是的,我想是的,我的印象是我可以以某种方式使用 .dll 文件。不是这样吗
    • 没有。但是你也许可以使用 C 版本?还是使用visual studio win32/64 控制台?
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-17
      • 2023-01-20
      • 2011-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-02
      相关资源
      最近更新 更多