【发布时间】:2015-06-25 08:37:24
【问题描述】:
嗨,imy 项目可以识别不存在 2 次的变量的双重定义。我想通过更改我的代码并重新编译它会卡住一些方法。
LedMatrix7219.cpp.o:(.data.Alphaletter+0x0): `Alphaletter'的多重定义 LedController.cpp.o:(.data.Alphaletter+0x0): first 在这里定义
LedMatrix7219.cpp.o:在函数“循环”中 LedController.cpp.o:(.bss.arr+0x0): 首先定义在这里
LedMatrix7219.cpp.o:在函数“循环”中 LedController.cpp.o:(.data.Alphaletter2+0x0): 这里先定义
collect2.exe*:error: ld 返回 1 个退出状态
我有一个 LedController 类和一个标头 LettersDefinition.h
所有的标题都是这样开始的:
我包含一个结构和一个从 LetterDefinition.h 到 LedController 的枚举,所以在标题中我需要包含 LetterDefinition.h 以进行一定的打击。
#ifndef __LEDCONTROLLER_H__
#define __LEDCONTROLLER_H__
#include <Arduino.h>
#include "LettersDefinition.h"
LetterStruct finalText;
String theText="Test";
void test();
//it does some extra staff
#endif //__LEDCONTROLLER_H__
以及字母定义的标题。
#ifndef LETTERSDEFINITION_H_
#define LETTERSDEFINITION_H_
#include "arduino.h"
#include <avr/pgmspace.h>
struct LetterStruct{
lettersEnum name;
uint8_t size;
uint8_t columnSize[5];
uint8_t data[18];
}Alphaletter;
#endif /* LETTERSDEFINITION_H_ */
从我的主 .ide 文件中,我调用了 Ledcontroller 的测试函数,我得到了你在上面看到的错误。测试函数只是检查 LetterStruct.name 变量而已。
我的 .ide 类似于:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
#include "LedController.h"
LedController controller;
void setup()
{
//irrelevant inits
}
void loop()
{
controller.test();
delay(2000);
}
如果我从 LedController.h 中删除 #include "LettersDefinition.h",则此错误将其定位为未在 LedController.h 中定义 LetterStruct 的错误,这是正常的,因为我必须添加 LettersDefinition.h为了被定义。
【问题讨论】:
-
你确定你不是想把它定义为一个类型吗?
-
如你所见,我只是声明了一个特定类型的字母结构,这就是我所做的一切。在 letterDefinition.h 中定义了敲击
-
是的,你在两个不同的编译单元中声明它。
-
标头不是编译单元。
标签: arduino code-cleanup atmel atmelstudio