无法编译 ESP-IDF 示例项目

时间:2021-06-03 07:05:23

标签: esp32 esp-idf

我正在尝试编译我的第一个 ESP32 示例项目。 我使用所有最新工具设置了 Visual Studio Code。 (Python、工具链等)。 我不知道我到底需要什么,因为我是这个环境的新手,所以可能我错过了一些东西。

我按照关于如何创建和编译第一个项目的用户指南,我使用了示例文件夹中的 Blink 项目。

这是我得到的。

> Executing task: cmake -G Ninja .. <

-- Project is not inside a git repository, or git repository has no commits; will not use 'git describe' to determine PROJECT_VER.
-- Building ESP-IDF components for target esp32s2
-- Checking Python dependencies...
Python requirements from C:\Users\dmitryke\esp\esp-idf\requirements.txt are satisfied.
-- Project sdkconfig file C:/ESP32_projects/blink/sdkconfig
Loading defaults file C:/ESP32_projects/blink/sdkconfig.defaults...
-- Components:
-- Component paths:
-- Configuring done
-- Generating done
-- Build files have been written to C:/ESP32_projects/blink/build

The terminal will be reused by tasks, press any key to close it.

> Executing task: cmake --build . <

[1/1] Linking C executable blink.elf
FAILED: blink.elf 
cmd.exe /C "cd . && C:\Users\dmitryke\.espressif\tools\xtensa-esp32s2-elf\esp-2020r3-8.4.0\xtensa-esp32s2-elf\bin\xtensa-esp32s2-elf-gcc.exe -mlongcalls   CMakeFiles/blink.elf.dir/project_elf_src.c.obj  -o blink.elf  -Wl,--cref -Wl,--Map=C:/ESP32_projects/blink/build/blink.map  -fno-rtti  -fno-lto && cd ."
c:/users/dmitryke/.espressif/tools/xtensa-esp32s2-elf/esp-2020r3-8.4.0/xtensa-esp32s2-elf/bin/../lib/gcc/xtensa-esp32s2-elf/8.4.0/../../../../xtensa-esp32s2-elf/bin/ld.exe: c:/users/dmitryke/.espressif/tools/xtensa-esp32s2-elf/esp-2020r3-8.4.0/xtensa-esp32s2-elf/bin/../lib/gcc/xtensa-esp32s2-elf/8.4.0/../../../../xtensa-esp32s2-elf/lib/no-rtti/crt0.o:(.literal+0x0): undefined reference to `main'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
The terminal process "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command cmake --build ." terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

我从blink.c中删除了所有内容以避免代码错误。

blink.c

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"

/* Can use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
   or you can edit the following line and set a number here.
*/
#define BLINK_GPIO 0x01

void app_main(void)
{
    while(1) {    }
}

另一个问题,有一个选项可以运行 idf.py menuconfig。 有时它有效,有时它说:

C:\ESP32_projects\blink>idf.py menuconfig
'idf.py' is not recognized as an internal or external command,
operable program or batch file.

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:0)

所有 ESP IDF 任务(cmake、idf.py 等)都必须在准备好的环境中运行。我首先会失去 VSC(因为它只是另一个潜在的故障点)并使用基本的 ESP IDF command prompt。尝试运行 idf.py menuconfigidf.py buildidf.py -p COMx flash 以配置、构建和刷新您的测试项目。

一旦您确认 ESP IDF 环境和您的项目正常工作,请返回 VSC 并查看那里出了什么问题。

作为一个工作示例,这是我如何在我的机器(Linux、ESP IDF v4.2.1)上从头开始编译相同的示例项目:

$ cp -r ~/esp-idf/examples/get-started/blink/ .
$ cd blink
$ idf.py build
Running cmake in directory /home/tarmo/tmp/espidftest/blink/build                                                                                                                                                  
Executing "cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DESP_PLATFORM=1 -DCCACHE_ENABLE=0 /home/tarmo/tmp/espidftest/blink"... 
-- Found Git: /usr/bin/git (found version "2.30.2")                                                                                                                                                                
-- IDF_TARGET not set, using default target: esp32                                                                                                                                                                 
-- The C compiler identification is GNU 8.4.0                                                                                                                                                                      
-- The CXX compiler identification is GNU 8.4.0   

[SNIP]

esptool.py v3.0                                                                                                                                                                                                    
Generated /home/tarmo/tmp/espidftest/blink/build/bootloader/bootloader.bin                                                                                                                                         
[934/934] Generating binary image from built executable                                                                                                                                                            
esptool.py v3.0                                                                                                                                                                                                    
Generated /home/tarmo/tmp/espidftest/blink/build/blink.bin                                                                                                                                                         
                                                                                                                                                                                                                   
Project build complete. To flash, run this command:                                                                                                                                                                
/home/tarmo/espressif/python_env/idf4.2_py3.9_env/bin/python ../esp-idf/components/esptool_py/esptool/esptool.py -p (PORT) -b 921600 --before default_reset
 --after hard_reset --chip esp32  write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/blink.bin
or run 'idf.py -p (PORT) flash'
$ ls -lha
drwxr-xr-x 8 tarmo tarmo 4,0K juuni  4 12:26 build
-rw-r--r-- 1 tarmo tarmo  234 juuni  4 12:25 CMakeLists.txt
-rw-r--r-- 1 tarmo tarmo 1,5K juuni  4 12:25 example_test.py
drwxr-xr-x 3 tarmo tarmo 4,0K juuni  4 12:26 main
-rw-r--r-- 1 tarmo tarmo  177 juuni  4 12:25 Makefile
-rw-r--r-- 1 tarmo tarmo  157 juuni  4 12:25 README.md
-rw-r--r-- 1 tarmo tarmo  33K juuni  4 12:25 sdkconfig
-rw-r--r-- 1 tarmo tarmo    3 juuni  4 12:25 sdkconfig.defaults

答案 1 :(得分:0)

命令窗口不太重要,我让它工作了。 我的主要问题是主要没有被链接。