Keil编译错误error: #20: identifier "XXXX" is undefined

问题:
在使用Keil编译工程时,经常遇到提示identifier "XXXX"未定义的error信息。

Build target 'canopen_mx_v1d61'
compiling main.c...
../Src/main.c(104): warning:  #223-D: function "setNodeId" declared implicitly
      setNodeId(&TestMaster_Data, 0);                 // nodeID); // Master ID is 0
../Src/main.c(104): error:  #20: identifier "TestMaster_Data" is undefined
      setNodeId(&TestMaster_Data, 0);                 // nodeID); // Master ID is 0
../Src/main.c(105): warning:  #223-D: function "setState" declared implicitly
      setState(&TestMaster_Data, Initialisation);      // Init the state
../Src/main.c(105): error:  #20: identifier "Initialisation" is undefined
      setState(&TestMaster_Data, Initialisation);      // Init the state
../Src/main.c(188): warning:  #223-D: function "TimerForCan" declared implicitly
      TimerForCan();
../Src/main.c: 3 warnings, 2 errors
"canopen_mx_v1d61\canopen_mx_v1d61.axf" - 2 Error(s), 3 Warning(s).

添加了Initialisation标识符被定义的头文件states.h,编译后仍有错误提示:

Build target 'canopen_mx_v1d61'
compiling main.c...
..\CANFestival\inc\lifegrd.h(66): error:  #20: identifier "e_nodeState" is undefined
  typedef void (*post_SlaveStateChange_t)(CO_Data*, UNS8, e_nodeState);
..\CANFestival\inc\lifegrd.h(67): error:  #20: identifier "e_nodeState" is undefined
  void _post_SlaveStateChange(CO_Data* d, UNS8 nodeId, e_nodeState newNodeState);
..\CANFestival\inc\lifegrd.h(118): error:  #20: identifier "e_nodeState" is undefined
  e_nodeState getNodeState (CO_Data* d, UNS8 nodeId);
..\CANFestival\inc\data.h(74): error:  #20: identifier "e_nodeState" is undefined
  	e_nodeState nodeState;
..\CANFestival\inc\data.h(75): error:  #20: identifier "s_state_communication" is undefined
  	s_state_communication CurrentCommunicationState;
..\CANFestival\inc\data.h(76): error:  #20: identifier "initialisation_t" is undefined
  	initialisation_t initialisation;
..\CANFestival\inc\data.h(77): error:  #20: identifier "preOperational_t" is undefined
  	preOperational_t preOperational;
..\CANFestival\inc\data.h(78): error:  #20: identifier "operational_t" is undefined
  	operational_t operational;
..\CANFestival\inc\data.h(79): error:  #20: identifier "stopped_t" is undefined
  	stopped_t stopped;
..\CANFestival\inc\data.h(90): error:  #20: identifier "e_nodeState" is undefined
  	e_nodeState NMTable[NMT_MAX_NODE_ID]; 
../Src/main.c(104): error:  #20: identifier "TestMaster_Data" is undefined
      setNodeId(&TestMaster_Data, 0);                 // nodeID); // Master ID is 0
../Src/main.c(188): warning:  #223-D: function "TimerForCan" declared implicitly
      TimerForCan();
../Src/main.c: 1 warning, 11 errors
"canopen_mx_v1d61\canopen_mx_v1d61.axf" - 11 Error(s), 1 Warning(s).

提示e_nodeState在lifegrd.h中没有定义,将e_nodeState的定义头文件states.h添加到lifegrd.h中,再次编译,错误依旧。

解决办法:
1、编译器报错的地方并不准确。
比如第二次编译时报头文件lifegrd.h中e_nodeState未定义,
但是将e_nodeState的定义头文件include到lifegrd.h中,
编译仍然有错。

2、正确的做法是:
仔细查看第一个error信息是在编译哪个c文件时出现的,
把第一个未定义的数据类型的头文件添加到该c文件中。

按照上述原则,
从首次编译出错的第一个error:
error: #20: identifier “TestMaster_Data” is undefined。
是在编译main.c的时候出错的,
找到定义TestMaster_Data的头文件TestMaster.h,
将TestMaster.h文件include到main.c中,
重新编译,错误消失。

Build target 'canopen_mx_v1d61'
compiling main.c...
../Src/main.c(188): warning:  #223-D: function "TimerForCan" declared implicitly
      TimerForCan();
../Src/main.c: 1 warning, 0 errors
linking...
Program Size: Code=9956 RO-data=724 RW-data=1924 ZI-data=1348  
FromELF: creating hex file...
"canopen_mx_v1d61\canopen_mx_v1d61.axf" - 0 Error(s), 1 Warning(s).

问题解决。

*** Using Compiler 'V5.06 update 3 (build 300)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Rebuild target 'takeatry' assembling startup_stm32f103xe.s... compiling main.c... ../Core/Inc/main.h(49): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ ../Core/Src/main.c(4): error: #20: identifier "TASK_IDLE" is undefined TaskMode current_task = TASK_IDLE; ../Core/Src/main.c(27): warning: #223-D: function "Key_Scan" declared implicitly if (Key_Scan(KEY1_PIN, KEY1_PORT) && !task_running) { ../Core/Src/main.c(27): error: #20: identifier "KEY1_PIN" is undefined if (Key_Scan(KEY1_PIN, KEY1_PORT) && !task_running) { ../Core/Src/main.c(27): error: #20: identifier "KEY1_PORT" is undefined if (Key_Scan(KEY1_PIN, KEY1_PORT) && !task_running) { ../Core/Src/main.c(32): warning: #223-D: function "Key_Scan" declared implicitly if (Key_Scan(KEY2_PIN, KEY2_PORT) && !task_running) { ../Core/Src/main.c(32): error: #20: identifier "KEY2_PIN" is undefined if (Key_Scan(KEY2_PIN, KEY2_PORT) && !task_running) { ../Core/Src/main.c(32): error: #20: identifier "KEY2_PORT" is undefined if (Key_Scan(KEY2_PIN, KEY2_PORT) && !task_running) { ../Core/Src/main.c(37): warning: #223-D: function "Key_Scan" declared implicitly if (Key_Scan(KEY3_PIN, KEY3_PORT) && !task_running) { ../Core/Src/main.c(37): error: #20: identifier "KEY3_PIN" is undefined if (Key_Scan(KEY3_PIN, KEY3_PORT) && !task_running) { ../Core/Src/main.c(37): error: #20: identifier "KEY3_PORT" is undefined if (Key_Scan(KEY3_PIN, KEY3_PORT) && !task_running) { ../Core/Src/main.c(147): error: #159: declaration is incompatible with previous "Key_Scan" (declared at line 27) uint8_t Key_Scan(uint16_t pin, GPIO_TypeDef *port) { ../Core/Src/main.c(168): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ ../Core/Src/main.c: 5 warnings, 8 errors compiling stm32f1xx_hal_rcc_ex.c... compiling stm32f1xx_it.c... ../Core/Inc/main.h(49): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ ../Core/Src/stm32f1xx_it.c: 1 warning, 0 errors compiling buzzer.c... ../Core/Inc/main.h(49): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ buzzer.c(26): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ buzzer.c: 2 warnings, 0 errors compiling stm32f1xx_hal_gpio_ex.c... compiling stm32f1xx_hal.c... compiling motor.c... ../Core/Inc/main.h(49): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ motor.c(51): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ motor.c: 2 warnings, 0 errors compiling gpio.c... ../Core/Inc/main.h(49): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ ../Core/Src/gpio.c: 1 warning, 0 errors compiling stm32f1xx_hal_rcc.c... compiling stm32f1xx_hal_tim_ex.c... compiling sensor.c... ../Core/Inc/main.h(49): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ sensor.c(65): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ sensor.c: 2 warnings, 0 errors compiling stm32f1xx_hal_gpio.c... compiling stm32f1xx_hal_tim.c... compiling tim.c... ../Core/Inc/main.h(49): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ ../Core/Src/tim.c: 1 warning, 0 errors compiling stm32f1xx_hal_msp.c... ../Core/Inc/main.h(49): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ ../Core/Src/stm32f1xx_hal_msp.c: 1 warning, 0 errors compiling stm32f1xx_hal_dma.c... compiling stm32f1xx_hal_cortex.c... compiling stm32f1xx_hal_pwr.c... compiling stm32f1xx_hal_flash.c... compiling stm32f1xx_hal_flash_ex.c... compiling system_stm32f1xx.c... ../Core/Inc/main.h(49): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ ../Core/Src/system_stm32f1xx.c(67): warning: #1-D: last line of file ends without a newline /* ?募?末尾???? */ ../Core/Src/system_stm32f1xx.c: 2 warnings, 0 errors compiling stm32f1xx_hal_exti.c... "takeatry\takeatry.axf" - 8 Error(s), 17 Warning(s). Target not created. Build Time Elapsed: 00:02:10
最新发布
07-13
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值