很多小伙伴还是习惯在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_PATH
和 IDF_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
- Build the project:
Navigate to View > Command Palette.
Type ESP-IDF: Build your Project and select the command to build the project.
- 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下都有。
先搁置