一个ESP-arduino项目,在platformIO中创建后,其目录结构是这样的:
作为开发者,大多数时间只需要在三个文件夹下编写程序:include、lib、src
新建项目后,这三个文件夹会自动生成。便于后续演示,我在lib中创建了两个库,分别是bbbb和dddd。
先说src文件夹:
这个文件夹下默认生成一个main函数的cpp文件,作为程序的入口,.cpp告诉开发者它支持c++编写。
还可以在这个文件夹下增加其它的自写的.c/cpp和.h文件,共main文件引用。
然后是include文件夹:
这个文件夹在README中的描述为(节选):
…A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located insrc
folder
by including it, with the C preprocessing directive `#include’…Including a header file produces the same results as copying the header file…
…Including a header file produces the same results as copying the header file into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place…
原文主旨是你可以将src文件夹里的.h文件放到这个文件夹下,效果是一样的并且还可以节省将头文件拷贝到每个需求源文件的工作(Including a header file produces the same results as copying the header file into each source file that needs it. )(雾?这句确实没搞懂什么意思)。总之就是可以将上文的src文件夹里的.h头文件放到这供src中的.c/cpp文件使用。
最后,lib文件夹:
如果你需要引入第3方库,或者自建库,可以在这里建立。形式可按上图,一个子文件夹下是一个库。
关于这个library.json的描述可见官方文档:
https://docs.platformio.org/en/latest/manifests/library-json/fields/build/includedir.html
简单用用没这个json也行。