我正在我的esp32s2上尝试一个非常简单的案例。构建看起来还不错,但是链接不太好。
该代码的目的是发送击键(esp32s2作为USB设备)。其内容如下:
#include "tinyusb.h"
#include "class/hid/hid_device.h"
#include "tusb.h"
enum {
ITF_KEYBOARD = 1,
ITF_MOUSE = 0
};
void app_main(void)
{
tusb_init();
tud_task(); // tinyusb device task
uint8_t keycode[6] = { 0 };
keycode[0] = 0x04 ; //HID_KEY_A;
tud_hid_n_keyboard_report(ITF_KEYBOARD, 0, 0, keycode);
}
主文件夹中的CMakeLists.txt类似于:
idf_component_register(SRCS main.c
INCLUDE_DIRS ".")
主文件夹旁边的CMakeLists.txt类似于:
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(test)
而makefile就像:
PROJECT_NAME := project_name
include $(IDF_PATH)/make/project.mk
我还尝试在我的项目中复制lib _device.c/h,它运行良好,但是链接仍然不起作用。
当我构建该项目时,我得到了以下错误:
[ 99%] Linking C static library libmain.a
[ 99%] Built target __idf_main
[ 99%] Generating ld/sections.ld
[ 99%] Built target __ldgen_output_sections.ld
[ 99%] Linking CXX executable test.elf
/home/me/.espressif/tools/xtensa-esp32s2-elf/esp-2021r2-8.4.0/xtensa-esp32s2-elf/bin/../lib/gcc/xtensa-esp32s2-elf/8.4.0/../../../../xtensa-esp32s2-elf/bin/ld: esp-idf/main/libmain.a(main.c.obj):(.literal.app_main+0x0): undefined reference to `tud_hid_n_keyboard_report'
/home/me/.espressif/tools/xtensa-esp32s2-elf/esp-2021r2-8.4.0/xtensa-esp32s2-elf/bin/../lib/gcc/xtensa-esp32s2-elf/8.4.0/../../../../xtensa-esp32s2-elf/bin/ld: esp-idf/main/libmain.a(main.c.obj): in function `app_main':
/home/me/My_project/project_test_HID/main/main.c:37: undefined reference to `tud_hid_n_keyboard_report'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test.elf.dir/build.make:538 : test.elf] Erreur 1
make[1]: *** [CMakeFiles/Makefile2:2458 : CMakeFiles/test.elf.dir/all] Erreur 2
make: *** [Makefile:149 : all] Erreur 2
make failed with exit code 2
如果你有任何想法,请告诉我:)
谢谢
问候
发布于 2022-02-12 13:40:51
您将从一个名为"tinyusb“的ESP-下手组件中包含标题(这是它的源代码:esp-idf/components/tinyusb
中目录的名称)。但是,如果您使用的是组件,您必须告诉构建系统这一点-否则它将不会拉这个组件的实现,你会得到链接器错误。
您可以通过您的主CMakeLists.txt将它拉进来,如下所示:
idf_component_register(SRCS main.c
INCLUDE_DIRS "."
REQUIRES "tinyusb")
这一切在ESP以色列国防军构建系统文档中或多或少都解释得很清楚
https://stackoverflow.com/questions/71090220
复制相似问题