使用 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](https://www.visualmicro.com/page/User-Guide.aspx?doc=Getting-started.html "Installation of Visual Micro for Arduino") 最后还是运行未成功,估计1是 CMakeListsPrivate.txt文件不在,2是这个报错: No SOURCES given to target: Z_DUMMY_TARGET 。这个报错在VSCode和Visual Studio 2022下都有。 先搁置

相关推荐
禺垣2 小时前
区块链技术概述
大数据·人工智能·分布式·物联网·去中心化·区块链
2401_858286113 小时前
OS11.【Linux】vim文本编辑器
linux·运维·服务器·编辑器·vim
love530love5 小时前
【PyCharm必会基础】正确移除解释器及虚拟环境(以 Poetry 为例 )
开发语言·ide·windows·笔记·python·pycharm
梦星辰.6 小时前
VSCode CUDA C++进行Linux远程开发
linux·c++·vscode
小智学长 | 嵌入式7 小时前
SOC-ESP32S3部分:36-适配自己的板卡
单片机·物联网·esp32
*Lisen7 小时前
重新安装解决mac vscode点击不能跳转问题
ide·vscode·macos
小男孩tom8 小时前
vscode
ide·vscode·编辑器
打码人的日常分享15 小时前
物联网智慧医院建设方案(PPT)
大数据·物联网·架构·流程图·智慧城市·制造
Morpheon16 小时前
Cursor 1.0 版本 GitHub MCP 全面指南:从安装到工作流增强
ide·github·cursor·mcp
猿小猴子17 小时前
主流 AI IDE 之一的 Cursor 介绍
ide·人工智能·cursor