使用 ESP-IDF 进行esp32-c3开发第四步:VSCode里安装ESP-IDF插件

很多小伙伴还是习惯在VSCode里写代码,所以今天进行了--使用 ESP-IDF 进行esp32-c3开发第四步:VSCode里安装ESP-IDF插件

安装和配置

首先到VSCode的插件页面,搜索esp,排名第一的就是ESP-IDF插件,点击安装即可。

在命令列表里,选择"Configure ESP-IDF Extension " ,或者直接按F1,选择"ESP-IDF: Configure ESP-IDF Extension"

注意,按F1选择是"ESP-IDF: Configure ESP-IDF Extension" ,跟命令列表里的不一样。

选择"Express"并选择下载服务器。在国内建议选择espressif 。后面几个版本、路径等选项,基本按照默认就行。

注意IDF_TOOLS_PATHIDF_PATH.不要雷同就行。

后面就是漫长的安装过程

最后安装完成,显示下面选项页面:

Quick actions

New project

Import project

Show examples

Components manager

可以选择New project来创建项目,Import Project 来导入项目。还可以用Show examples来看官方的例子代码。

现在让咱们用一个简单例子和一个复杂例子来测试一下

简单例子

创建例子

直接点击Show examples ,出来这个界面:The ESP Component Registry

然后选:Sample project

选好放置的目录,出现提示:Do you trust the authors of the files in this folder?

选择trust ,一个例子就创建好了。以后自己写项目,可以用这个项目作为基础架构。

查看项目,发现main.cpp里面是只有一个空main函数。

这时候VSCode自动询问是否下载:C/C++ Extension Pack

当然是下!

尝试编译

右键CMakeLists.txt文件,执行build all,结果提示:

复制代码
[cmake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
[cmake] -- Configuring incomplete, errors occurred!
[proc] The command: "e:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE --no-warn-unused-cli -SE:/work/esp/sample_project -Be:/work/esp/sample_project/build -G "Visual Studio 17 2022" -T host=x64 -A x64 exited with code: 1

感觉有点不对劲啊

有点明白了,它需要一个docker容器!

加进去了,没有啥变化啊

再次编译

点击View > Command Palette

选中ESP-IDF: Build your Project 开始编译

编译报错:

ninja: error: loading 'build.ninja': 绯荤粺鎵句笉鍒版寚瀹氱殑鏂囦欢銆?

原来是已经有了一个build文件夹,那个文件夹应该是用x86编译的时候生成的。将build文件夹删除,重新开始编译,成功!

Total image size: 177672 bytes (.bin may be padded larger)

下面是文档节选:

Build the Project

  1. Build the project:
  • Navigate to View > Command Palette.

  • Type ESP-IDF: Build your Project and select the command to build the project.

  1. A new terminal being launched with the build output and a notification bar with Building Project message until it is done then a Build done message when finished.

Sample project

(See the README.md file in the upper level 'examples' directory for more information about examples.)

This is the simplest buildable example. The example is used by command idf.py create-project

that copies the project to user specified path and set it's name. For more information follow the docs page

尝试复杂例子(未成功)

复杂例子就用稚晖君的例子吧

下载源代码:

复制代码
git clone https://github.com/peng-zhihui/HoloCubic

进入HoloCubic/2.Firmware目录,打开项目

VSCode里坎坷的编译过程(未成功)

打开目录holycubic-fw,

build报错:

复制代码
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:13 (project):
  No CMAKE_C_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment    
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:13 (project):
  No CMAKE_CXX_COMPILER could be found.    

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "E:/github/HoloCubic/2.Firmware/HoloCubic-fw/build/CMakeFiles/CMakeOutput.log".
See also "E:/github/HoloCubic/2.Firmware/HoloCubic-fw/build/CMakeFiles/CMakeError.log".

 *  The terminal process "e:\Espressif\tools\tools\cmake\3.24.0\bin\cmake.exe '-G', 'Ninja', '-DPYTHON_DEPS_CHECKED=1', '-DESP_PLATFORM=1', '-B', 'e:\github\HoloCubic\2.Firmware\HoloCubic-fw\build', '-S', 'e:\github\HoloCubic\2.Firmware\HoloCubic-fw', '-DSDKCONFIG=e:\github\HoloCubic\2.Firmware\HoloCubic-fw\sdkconfig'" terminated with exit code: 1. 

Tell CMake where to find the compiler by setting either the environment

variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path

to the compiler, or to the compiler name if it is in the PATH.

找到问题啦!

原来需要在配置的时候,再配置一下:The ESP Component Registry

其实不是..

再Cmake选项里,找到Build,选择64 x86,然后就会显示出CXX啦,其实不是

看Readme.txt,发现是用了Visual Macro

自己的VSCode是2022,所以下载了2022版:

Download the Arduino IDE for Visual Studio

开始安装:

安装完毕

安装之后,重启VSCode,显示识别出来了cxx

cmake -- The C compiler identification is MSVC 19.37.32822.0

cmake -- The CXX compiler identification is MSVC 19.37.32822.0

晕,看明白了,是Visual Studio ,我还在VSCode里面找.....

重新安装配置Visual Studio 2022(未编译成功)

cxx那句pass了,现在报错:

严重性 代码 说明 项目 文件 行 禁止显示状态

错误 CMake Error at E:\github\HoloCubic\2.Firmware\HoloCubic-fw\CMakeLists.txt:15 (include):

include could not find requested file:

CMakeListsPrivate.txt HoloCubic-fw E:\github\HoloCubic\2.Firmware\HoloCubic-fw\CMakeLists.txt 15

很正常,确实没有CMakeListsPrivate.txt这个文件

把15行屏蔽掉,

复制代码
# include(CMakeListsPrivate.txt)

提示:

Visual Studio 需要 MSVC 工具集版本"14.36.32502"。建议以管理员身份运行 Visual Studio,以解决可能出现的任何问题。

尽管win10管理面板,找到Visual Studio 2022 ,安装msvc

按照提示,找到MSVC的14.36版本,装上。有好几个,分不清哪个,都装上。

具体说明见:Installation of Visual Micro for Arduino

最后还是运行未成功,估计1是 CMakeListsPrivate.txt文件不在,2是这个报错: No SOURCES given to target: Z_DUMMY_TARGET 。这个报错在VSCode和Visual Studio 2022下都有。

先搁置

相关推荐
数字新视界3 小时前
国产信创动环监控系统助力环境安全管控创新
物联网·安全·电力监控系统·用电安全·大榕树
单片机杂货铺5 小时前
基于STM32的智能市政清洁小车系统设计
stm32·单片机·嵌入式硬件·物联网·硬件工程
电化学仪器白超7 小时前
禹衡光栅长度计精度评测:基于国标0级氧化锆量块的校正与数据分析
python·单片机·嵌入式硬件·物联网·自动化
骇客野人8 小时前
VSCode 安装 Trae(Trae AI: Coding Assistant)完整教程
ide·vscode·编辑器
骇客野人8 小时前
IDEA 安装 Trae(TRAE AI: Coding Assistant)完整步骤
java·ide·intellij-idea
2501_915921439 小时前
SwiftUI开发框架入门指南:从基础到实战
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
hongmai6668889 小时前
ESP8684-WROOM-02C:一块被低估的RISC-V Wi-Fi模组
单片机·嵌入式硬件·物联网·5g·智能路由器·risc-v
骇客野人9 小时前
IntelliJ IDEA 使用技巧
java·ide·intellij-idea
senmuleishi10 小时前
持续发力嵌入式AI IDE,攻坚大科学装置电源解决方案
ide·人工智能
骇客野人10 小时前
VSCode 高效使用技巧
ide·vscode·编辑器