在Arduino的IDE中包含自己的头文件



我想包含我在主Arduino代码中创建的头文件。不幸的是,在编译时,我得到错误消息,无法找到头文件。

我在windows 10上使用Arduino IDE 2.0.3,到目前为止没有出现重大问题。

这是,我所做的,到目前为止,我所做的最好的知识和各种网站,我用作为一个指南做了步骤1到3显然工作(即编译|这是我第一次尝试使用我自己的头文件btw):

  1. 创建工作主草图
  2. 在main中创建类
  3. 创建自己的文件(.h)在同一文件夹的主
    • #include <file.h>#include "file.h"都产生文件未找到错误
  4. 文件具有只读(rw-r——r——)权限组和其他(对我来说似乎足够了)
  5. 创建file.h向上或向下一个目录级别

那么,这是我的剥离代码产生的错误和错误消息:

filesetup:

../project1/project/
project.ino  classfile.h

project.ino:

#include <classfile.h>
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("hello world!");
delay(1000);
}

classfile.h:

#ifndef MY_CLASS_H
#define MY_CLASS_H
#include <Arduino.h>
//usefull class
#endif

使用Arduino IDE 2.0.3:Copilation错误:

Using board 'nano' from platform in folder: C:UsersxAppDataLocalArduino15packagesarduinohardwareavr1.8.6
Using core 'arduino' from platform in folder: C:UsersxAppDataLocalArduino15packagesarduinohardwareavr1.8.6
Detecting libraries used...
"C:\Users\x\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino" "-IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\eightanaloginputs" "C:\Users\x\AppData\Local\Temp\arduino-sketch-24B7CD866BBD71D5C48AF128C6D936B9\sketch\project.ino.cpp" -o nul
Alternatives for classfile.h: []
ResolveLibrary(classfile.h)
-> candidates: []
C:UsersxDesktopprojectproject.ino:1:10: fatal error: classfile.h: No such file or directory
#include <classfile.h>
^~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: classfile.h: No such file or directory

我该怎么做,来解决我的问题?

我发现文件必须以.hpp结尾(常见的c++头文件结束了这个约定,在arduino ide中很难实现)包含必须使用">而不是<>so:

classfile.hpp可以使用#include "classfile.hpp">对于我的代码的成功验证和复杂化。

如果你碰巧知道这是否可以在某个地方修改,请告诉我。

最新更新