打印
[其他]

Error: L6200E: Symbol FLASH_ADDRESS_BUF multiply defined (by usart.o and main.o)交叉定义

[复制链接]
724|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
nawu|  楼主 | 2023-9-19 12:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
编译时也许会告诉你重复定义分别出现在哪里。
需要注意的是,如果把变量移动到某个.h文件里,可能会导致有多个.c文件引用该头文件,进而产生多个该变量的定义,所以C语言里有要求,定义变量在.c里,声明在.h里。定义和声明用是否有extern来区分,有extern的是声明,多次出现也无所谓;没有extern的是定义,这个只能出现一次
错误写法
.h 里面写这个

extern const unsigned int FLASH_ADDRESS_BUF[ = {\
  0x0800A000,0x0800A400,0x0800A800,0x0800AC00,0x0800B000,0x0800B400,0x0800B800,0x0800BC00,\
  0x0800C000,0x0800C400,0x0800C800,0x0800CC00,0x0800D000,0x0800D400,0x0800D800,0x0800DC00,\
  0x0800E000,0x0800E400,0x0800E800,0x0800EC00,0x0800F000,0x0800F400,0x0800F800,0x0800FC00,\
  0x08010000,0x08010400,0x08010800,0x08010C00,0x08011000,0x08011400,0x08011800,0x08011C00,\
  0x08012000,0x08012400,0x08012800,0x08012C00,0x08013000,0x08013400,0x08013800,0x08013C00,\
  0x08014000,0x08014400,0x08014800,0x08014C00,0x08015000,0x08015400,0x08015800,0x08015C00,\
  0x08016000,0x08016400,0x08016800,0x08016C00,0x08017000,0x08017400,0x08017800,0x08017C00,\
  0x08018000,0x08018400,0x08018800,0x08018C00,0x08019000,0x08019400,0x08019800,0x08019C00,\
  0x0801A000,0x0801A400,0x0801A800,0x0801AC00,0x0801B000,0x0801B400,0x0801B800,0x0801BC00,\
  0x0801C000,0x0801C400,0x0801C800,0x0801CC00,0x0801D000,0x0801D400,0x0801D800,0x0801DC00,\
  0x0801E000,0x0801E400,0x0801E800,0x0801EC00,0x0801F000,0x0801F400,0x0801F800,0x0801FC00};];
extern unsigned char Sector_Count;  //用于读写扇区地址选择,指向FLASH_ADDRESS_BUF的地址


.c里面写这个

const unsigned int FLASH_ADDRESS_BUF[128-40];
unsigned char Sector_Count = 0;  //用于读写扇区地址选择,指向FLASH_ADDRESS_BUF的地址


修改成
.h写这个

extern const unsigned int FLASH_ADDRESS_BUF[128 - 40];
extern unsigned char Sector_Count;  //用于读写扇区地址选择,指向FLASH_ADDRESS_BUF的地址


.c写这个

const unsigned int FLASH_ADDRESS_BUF[] = {\
  0x0800A000,0x0800A400,0x0800A800,0x0800AC00,0x0800B000,0x0800B400,0x0800B800,0x0800BC00,\
  0x0800C000,0x0800C400,0x0800C800,0x0800CC00,0x0800D000,0x0800D400,0x0800D800,0x0800DC00,\
  0x0800E000,0x0800E400,0x0800E800,0x0800EC00,0x0800F000,0x0800F400,0x0800F800,0x0800FC00,\
  0x08010000,0x08010400,0x08010800,0x08010C00,0x08011000,0x08011400,0x08011800,0x08011C00,\
  0x08012000,0x08012400,0x08012800,0x08012C00,0x08013000,0x08013400,0x08013800,0x08013C00,\
  0x08014000,0x08014400,0x08014800,0x08014C00,0x08015000,0x08015400,0x08015800,0x08015C00,\
  0x08016000,0x08016400,0x08016800,0x08016C00,0x08017000,0x08017400,0x08017800,0x08017C00,\
  0x08018000,0x08018400,0x08018800,0x08018C00,0x08019000,0x08019400,0x08019800,0x08019C00,\
  0x0801A000,0x0801A400,0x0801A800,0x0801AC00,0x0801B000,0x0801B400,0x0801B800,0x0801BC00,\
  0x0801C000,0x0801C400,0x0801C800,0x0801CC00,0x0801D000,0x0801D400,0x0801D800,0x0801DC00,\
  0x0801E000,0x0801E400,0x0801E800,0x0801EC00,0x0801F000,0x0801F400,0x0801F800,0x0801FC00};;
unsigned char Sector_Count = 0;  //用于读写扇区地址选择,指向FLASH_ADDRESS_BUF的地址
————————————————
版权声明:本文为CSDN博主「明东(Maxwell)」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Maxwell_321/article/details/120684447

使用特权

评论回复
沙发
tpgf| | 2023-10-12 11:41 | 只看该作者
为什么很多时候报错的位置并不是实际出问题的位置呢

使用特权

评论回复
板凳
kxsi| | 2023-10-12 11:53 | 只看该作者
头文件里边的这个地址 我们依据什么进行修改呢

使用特权

评论回复
地板
zljiu| | 2023-10-12 12:10 | 只看该作者
为什么会出现交叉定义?两个头文件出现了冲突?

使用特权

评论回复
5
磨砂| | 2023-10-12 13:16 | 只看该作者
多个.c文件只是引用的同一个头文件的数据啊  不存在重复定义的问题

使用特权

评论回复
6
晓伍| | 2023-10-12 13:44 | 只看该作者
这种问题都是小问题 因为在编译的阶段就能报送错误

使用特权

评论回复
7
aoyi| | 2023-10-12 20:46 | 只看该作者
有些地址不是用户可以操作的 在这种情况下更改的话 会报错吗

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

72

主题

3307

帖子

3

粉丝