关于OLED移植出现Symbol oled_pow multiply defined

  • Post author:
  • Post category:其他


问题

今天督促队友写代码,他反馈移植的OELD代码报错Symbol oled_pow multiply defined。我查看了一下,发现在main.c和SR04.c中都引用了OLED(#include “oled.h”)。如果将超声波代码里面的#include “oled.h”注释掉就没有报错了,我查看了他头文件,发现加上了#ifndef __OLED_H_#define __OLED_H_#endif。测试了几次还是一大堆的Symbol oled_pow multiply defined 报错。

报错

Robot_competition\Robot_competition.axf: Error: L6200E: Symbol F6x8 multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol F8X16 multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol Hzk multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol BMP multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol BMP1 multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol BMP2 multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol BMP3 multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol IIC_Start multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol IIC_Stop multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol IIC_Wait_Ack multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_Clear multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_Display_On multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_DrawBMP multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_GPIO multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_Init multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_Set_Pos multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_ShowCHinese multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_ShowChar multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_ShowNum multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_ShowString multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol OLED_WR_Byte multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol Write_IIC_Byte multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol Write_IIC_Command multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol Write_IIC_Data multiply defined (by main.o and sr04.o).
Robot_competition\Robot_competition.axf: Error: L6200E: Symbol oled_pow multiply defined (by main.o and sr04.o).

尝试过程

(1)于是我开始加入extern关键字,发现依旧无用。

(2)然后我就开始查看他的OLED代码,发现OLED代码似乎也没有问题。

(3)然后我突然想到了去字模库看看。后面发现,他将所有的字模变量定义都放在了.h文件。

(4)然后我突然想起我也遇到过类似的问题,然后搜索了一下,在头文件定义变量有什么问题。结果是得到:



头文件中不可以放变量的定义 !



一般头文件中只是放变量的声明,因为头文件要被其他文件包含#include,如果把定义放在头文件的话,就不能避免多次 定义变量 。

结论

我们的OLED字模变量定义应该放在.C文件中,而不是.h文件。只需要把.h文件剪切到.C文件即可。



版权声明:本文为qq_63922192原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。