VSCODE/platformIO项目下include、lib、src三个文件夹的作用

一个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 in src 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也行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值