将所有库保存在 Arduino 草图目录中 [英] Keeping all libraries in the Arduino sketch directory

查看:36
本文介绍了将所有库保存在 Arduino 草图目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你应该将任何外部库放在 arduino 安装目录的libraries"文件夹下,但我有一个项目使用了我为项目创建的几个库,主要是为了保留所有代码包含在主 pde 文件之外.但是,我尝试将库与主 PDE 文件放在同一目录中,以便我可以更轻松地在 subversion 中保持所有内容同步(我在多台计算机上处​​理此问题)并且我不想继续分别备份和同步库.此外,只是为了能够轻松压缩草图文件夹并知道它包含所需的一切.

I know that you are supposed to place any external libraries under the "libraries" folder of the arduino install directory, but I have a project that uses several libraries that I have created for the project and mainly to keep all that code self contained and out of the main pde file. However, I have tried to place the libraries in the same directory as the main PDE file so that I can more easily keep everything synced up in subversion (I work on this on multiple computers) and I don't want to have to keep going back and syncing up the libraries separately. Also, just for the sake of being able to easily zip of the sketch folder and know that it contains everything it needs.

我尝试将头文件作为新选项卡添加到草图中,但这似乎根本不起作用......甚至不在乎它们是否应该在 arduino IDE 中.

I've tried adding the header files to the sketch as a new tab, but that doesn't seem to work at all... don't even care if they should up in the arduino IDE.

我还尝试将库添加到子目录中的草图目录(我非常喜欢),然后链接到它们:

I've also tried adding the libraries to the sketch directory in subdirectories (what I would greatly prefer) and then linking to them as:

#include "mylib/mylib.h"

#include <mylib/mylib.h>

但这两者都会导致文件未找到错误.

But both of these result in file not found errors.

这可能吗?而且,如果是这样,我如何将它们包含在构建的主文件中?最好在他们自己的子目录中.

Is this possible? And, if so, how do I include them in the main file for building? Preferably in their own subdirectories.

推荐答案

我遇到了同样的问题.为 Arduino IDE > 1.8 解决了这个问题.根据参考资料(见底部链接),似乎是较新的 IDE (?) 的专长.

I had the same issue. Solved it for Arduino IDE > 1.8. Seems a specialty in newer IDEs (?) according to the reference (see bottom link).

在创建库文件夹之前,您必须添加一个src"子目录.所以基本上你的项目应该是这样的:

You have to add a "src" Subdirectory before creating a library folder. So essentially your project should look like this:

/SketchDir (with *.ino file)  
/SketchDir/src  
/SketchDir/src/yourLib (with .h and .cpp file)  

最后在你的草图中参考:

and finally in your sketch you reference:

#include "src/yourLib/yourLib.h"  

否则在我的情况下 - 如果我缺少src"文件夹 - 我收到错误消息,它找不到 yourLib.cpp 文件.

otherwise in my case - if I am missing the "src" folder - I get the error message that it cannot find the yourLib.cpp file.

注意:我使用的是 Windows 系统,以防它不同,实际上 VS Code 作为 Arduino IDE 的包装器.但是两个IDE都使用这种结构编译它.

Note: I am using a windows system in case it differs and actually VS Code as wrapper for Arduino IDE. But both IDE compile it with this structure.

参考资料:https://forum.arduino.cc/index.php?topic=445230.0

这篇关于将所有库保存在 Arduino 草图目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆