关于STM32头文件包含出现No such file or directory和 invalid redeclaration of type name...的问题

    用keil sdk编译STM32的程序时出现“.\inc\stm32f10x_conf.h(21): error:  #5: cannot open source input file "stm32f10x_type.h": No such file or directory”类似的问题,说明没有搜到此头文件,如果是用双引号 “  ” 包含的头文件,则问题肯定出在没有把此头文件放在工程文件夹内。

还有一个问题,已经把此头文件放在了工程文件夹内,但是编译时出现这个问题:.\inc\stm32f10x_type.h(28): error:  #256: invalid redeclaration of type name "s32" (declared at line487 of ".\inc\stm32f10x.h"),没有任何怀疑,错误提示已经明确地说s32这个名字已经在inc\stm32f10x.h的487行定义过,所以stm32f10x_type.h中对s32的定义属于重复定义,无效。

    那么为什么会出现重复定义呢? 通过双击该提示到stm32f10x_type.h定义s32的地方,以及到stm32f10x.h的第487行定义s32的地方,会发现果然有同样的定义,

如图所示:

           


这是不同的头文件,而且在stm32f10x.h这个头文件中会包含stm32f10x_type.h(如图,stm32f10x.h包含了另一个头文件stm32f10x_conf.h,而在stm32f10x_conf.h里面包含了stm32f10x_type.h,即相当于stm32f10x.h中包含stm32f10x_type.h——即①包含了②,②包含了③,那么①就包含了③,有点啰嗦,但会显得更清楚一些,呵呵),


为什么还会出现在这两个相关联的头文件中定义了同一个名字s32呢?

问题就出在版本上。

在我的这个工程中,因为我打算都用双引号 “  ” 来包含头文件,所以要把头文件都放到我的工程文件夹里,并设置好路径(这里不细说,有问题加后面的QQ联系)。问题就来了,stm32f10x.h这个头文件是keil mdk中的,路径为\keil mdk\ARM\INC\ST\STM32F10x,而stm32f10x_conf.h是来自我先前安装的IAR编译里的(前面说了,stm32f10x.h中是会包含stm32f10x_conf.h的。至于为什么会把IAR这个编译器中的头文件放进去,就不说了,呵呵),正确的方法是只是用一个编译器中的头文件,保证版本的一致性,在我的工程中,应该使用kei mdk中的stm32f10x_conf.h,而不是IAR中的。

那么我们看看这不同的编译器中的同名头文件有什么区别,如下图:


左边的是Keil中的,版本为V3.5.0,右边是IAR中的,版本为V1.0,版本不同!!!

版本不同,里面定义的内容不同,自然会出现不能替换的问题了。

所以要特别注意相关联的头文件(有包含关系的)是不是来自同一个版本。


如有问题,欢迎互相交流。

QQ:2524886219


*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin' Build target 'Target 1' compiling LightSensor.c... Hardware\LightSensor.c(2): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\LightSensor.c: 0 warnings, 1 error compiling LED.c... Hardware\LED.c(37): error: #20: identifier "KEY_S0" is undefined if(key_val == KEY_S0) { Hardware\LED.c(38): warning: #188-D: enumerated type mixed with another type flowMode = (flowMode + 1) % 3; Hardware\LED.c(53): error: #20: identifier "KEY_S1" is undefined if(key_val == KEY_S1) { Hardware\LED.c(54): warning: #188-D: enumerated type mixed with another type breathState = (breathState + 1) % 3; Hardware\LED.c(75): warning: #223-D: function "HAL_GetTick" declared implicitly if(flowMode != LED_FLOW_OFF && (HAL_GetTick() - lastUpdate > 200)) { Hardware\LED.c(93): warning: #223-D: function "HAL_GetTick" declared implicitly if(breathState == BREATH_ON && (HAL_GetTick() - lastUpdate > 10)) { Hardware\LED.c(34): warning: #177-D: variable "flowDir" was declared but never referenced static uint8_t flowDir = 0; // 0:宸︹啋鍙? 1:鍙斥啋宸? Hardware\LED.c: 5 warnings, 2 errors compiling OLED.c... Hardware\OLED.c(3): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\OLED.c: 0 warnings, 1 error compiling PWM.c... Hardware\common.h(6): error: #101: "RESET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #101: "SET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(8): error: #101: "DISABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #101: "ENABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\Start\stm32f10x.h") typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\PWM.c(25): error: #20: identifier "LED1_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED2_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED3_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED4_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED5_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED6_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED7_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED1_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED2_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED3_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED4_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED5_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED6_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED7_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c: 0 warnings, 21 errors compiling Buzzer.c... Hardware\Buzzer.c(28): error: #20: identifier "KEY_S2" is undefined if(key_val == KEY_S2) { Hardware\Buzzer.c(36): warning: #223-D: function "HAL_GetTick" declared implicitly if(buzzerState && (HAL_GetTick() - lastToggle > 500)) { Hardware\Buzzer.c(38): warning: #223-D: function "GPIO_ToggleBits" declared implicitly GPIO_ToggleBits(BUZZER_PORT, BUZZER_PIN); // 鍒囨崲鐘舵€? Hardware\Buzzer.c: 2 warnings, 1 error compiling main.c... .\Hardware\common.h(6): error: #101: "RESET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(6): error: #101: "SET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(6): error: #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(6): error: #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(8): error: #101: "DISABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; .\Hardware\common.h(8): error: #101: "ENABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; .\Hardware\common.h(8): error: #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\Start\stm32f10x.h") typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; User\main.c(22): warning: #223-D: function "delay_init" declared implicitly delay_init(); // 寤舵椂鍒濆鍖? User\main.c(27): error: #165: too few arguments in function call LightSensor_Init(); User\main.c(31): error: #140: too many arguments in function call u8 key = KEY_Scan(0); // 涓嶆敮鎸佽繛鎸? User\main.c(34): error: #20: identifier "KEY0_PRES" is undefined if (key == KEY0_PRES) User\main.c(37): warning: #223-D: function "LED_Flow_SetMode" declared implicitly LED_Flow_SetMode(sysState.ledFlowMode); User\main.c(41): error: #20: identifier "KEY1_PRES" is undefined if (key == KEY1_PRES) User\main.c(46): warning: #223-D: function "LED_Breath_SetState" declared implicitly LED_Breath_SetState(LED_BREATH_ON); User\main.c(46): error: #20: identifier "LED_BREATH_ON" is undefined LED_Breath_SetState(LED_BREATH_ON); User\main.c(47): warning: #223-D: function "LED_Breath_SetPeriod" declared implicitly LED_Breath_SetPeriod(500); // 500ms鍛ㄦ湡 User\main.c(52): warning: #223-D: function "LED_Breath_SetState" declared implicitly LED_Breath_SetState(LED_BREATH_OFF); User\main.c(52): error: #20: identifier "LED_BREATH_OFF" is undefined LED_Breath_SetState(LED_BREATH_OFF); User\main.c(57): error: #20: identifier "KEY2_PRES" is undefined if (key == KEY2_PRES) User\main.c(60): warning: #223-D: function "Buzzer_SetState" declared implicitly Buzzer_SetState(sysState.beepState); User\main.c(64): error: #20: identifier "KEY3_PRES" is undefined if (key == KEY3_PRES) User\main.c(69): warning: #223-D: function "OLED_DisplayOn" declared implicitly OLED_DisplayOn(); User\main.c(71): warning: #223-D: function "OLED_ShowPersonalInfo" declared implicitly OLED_ShowPersonalInfo(); User\main.c(75): warning: #223-D: function "OLED_DisplayOff" declared implicitly OLED_DisplayOff(); User\main.c(80): warning: #223-D: function "LED_Flow_Task" declared implicitly LED_Flow_Task(); User\main.c(83): warning: #223-D: function "LED_Breath_Task" declared implicitly LED_Breath_Task(); User\main.c(86): warning: #223-D: function "Buzzer_Task" declared implicitly Buzzer_Task(); User\main.c(91): warning: #223-D: function "OLED_UpdateLightState" declared implicitly OLED_UpdateLightState(); // 鏇存柊鍏夌収鐘舵€佹樉绀? User\main.c(94): warning: #223-D: function "delay_ms" declared implicitly delay_ms(10); User\main.c: 14 warnings, 15 errors ".\Objects\Project.axf" - 41 Error(s), 21 Warning(s). Target not created.
07-11
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin' Build target 'Target 1' compiling PWM.c... Hardware\common.h(6): error: #101: "RESET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #101: "SET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(8): error: #101: "DISABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #101: "ENABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\Start\stm32f10x.h") typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\PWM.c: 0 warnings, 7 errors compiling Buzzer.c... Hardware\Buzzer.c(28): error: #20: identifier "KEY_S2" is undefined if(key_val == KEY_S2) { Hardware\Buzzer.c(36): warning: #223-D: function "HAL_GetTick" declared implicitly if(buzzerState && (HAL_GetTick() - lastToggle > 500)) { Hardware\Buzzer.c(38): warning: #223-D: function "GPIO_ToggleBits" declared implicitly GPIO_ToggleBits(BUZZER_PORT, BUZZER_PIN); // 鍒囨崲鐘舵€? Hardware\Buzzer.c: 2 warnings, 1 error compiling LightSensor.c... Hardware\LightSensor.c(2): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\LightSensor.c: 0 warnings, 1 error compiling OLED.c... Hardware\OLED.c(3): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\OLED.c: 0 warnings, 1 error compiling main.c... .\Hardware\lightsensor.h(3): error: #3: #include file ".\Hardware\lightsensor.h" includes itself #include "lightsensor.h" // 去掉下划线[^1] User\main.c: 0 warnings, 1 error compiling Key.c... Hardware\Key.c(13): error: #20: identifier "KEY_S0_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S0_PIN; Hardware\Key.c(15): error: #20: identifier "KEY_S0_PORT" is undefined GPIO_Init(KEY_S0_PORT, &GPIO_InitStructure); Hardware\Key.c(18): error: #20: identifier "KEY_S1_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S1_PIN; Hardware\Key.c(19): error: #20: identifier "KEY_S1_PORT" is undefined GPIO_Init(KEY_S1_PORT, &GPIO_InitStructure); Hardware\Key.c(22): error: #20: identifier "KEY_S2_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S2_PIN; Hardware\Key.c(23): error: #20: identifier "KEY_S2_PORT" is undefined GPIO_Init(KEY_S2_PORT, &GPIO_InitStructure); Hardware\Key.c(26): error: #20: identifier "KEY_S3_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S3_PIN; Hardware\Key.c(27): error: #20: identifier "KEY_S3_PORT" is undefined GPIO_Init(KEY_S3_PORT, &GPIO_InitStructure); Hardware\Key.c(34): error: #20: identifier "KEY_S0_PORT" is undefined if(key_up && (GPIO_ReadInputDataBit(KEY_S0_PORT, KEY_S0_PIN) == Bit_SET || Hardware\Key.c(34): error: #20: identifier "KEY_S0_PIN" is undefined if(key_up && (GPIO_ReadInputDataBit(KEY_S0_PORT, KEY_S0_PIN) == Bit_SET || Hardware\Key.c(35): error: #20: identifier "KEY_S1_PORT" is undefined GPIO_ReadInputDataBit(KEY_S1_PORT, KEY_S1_PIN) == Bit_SET || Hardware\Key.c(35): error: #20: identifier "KEY_S1_PIN" is undefined GPIO_ReadInputDataBit(KEY_S1_PORT, KEY_S1_PIN) == Bit_SET || Hardware\Key.c(36): error: #20: identifier "KEY_S2_PORT" is undefined GPIO_ReadInputDataBit(KEY_S2_PORT, KEY_S2_PIN) == Bit_SET || Hardware\Key.c(36): error: #20: identifier "KEY_S2_PIN" is undefined GPIO_ReadInputDataBit(KEY_S2_PORT, KEY_S2_PIN) == Bit_SET || Hardware\Key.c(37): error: #20: identifier "KEY_S3_PORT" is undefined GPIO_ReadInputDataBit(KEY_S3_PORT, KEY_S3_PIN) == Bit_SET)) { Hardware\Key.c(37): error: #20: identifier "KEY_S3_PIN" is undefined GPIO_ReadInputDataBit(KEY_S3_PORT, KEY_S3_PIN) == Bit_SET)) { Hardware\Key.c(38): warning: #223-D: function "Delay_ms" declared implicitly Delay_ms(10); // 娑堟姈寤舵椂 Hardware\Key.c(48): error: #20: identifier "KEY_S3" is undefined return KEY_S3; Hardware\Key.c(57): error: #20: identifier "KEY_NONE" is undefined return KEY_NONE; Hardware\Key.c: 1 warning, 18 errors compiling LED.c... Hardware\LED.c(7): error: #20: identifier "LED_FlowMode" is undefined static LED_FlowMode flowMode = LED_FLOW_OFF; Hardware\LED.c(9): error: #20: identifier "BREATH_OFF" is undefined static BreathState breathState = BREATH_OFF; Hardware\LED.c(23): error: #20: identifier "LED_PINS" is undefined GPIO_InitStructure.GPIO_Pin = LED_PINS; Hardware\LED.c(37): error: #20: identifier "KEY_S0" is undefined if(key_val == KEY_S0) { Hardware\LED.c(40): error: #20: identifier "LED_PINS" is undefined GPIO_SetBits(LED_PORT, LED_PINS); // 鍏抽棴鎵€鏈塋ED Hardware\LED.c(47): error: #20: identifier "LED_FLOW_FORWARD" is undefined case LED_FLOW_FORWARD: OLED_ShowString(72, 0, "FWD"); break; Hardware\LED.c(48): error: #20: identifier "LED_FLOW_BACKWARD" is undefined case LED_FLOW_BACKWARD: OLED_ShowString(72, 0, "REV"); break; Hardware\LED.c(53): error: #20: identifier "KEY_S1" is undefined if(key_val == KEY_S1) { Hardware\LED.c(54): warning: #188-D: enumerated type mixed with another type breathState = (breathState + 1) % 3; Hardware\LED.c(61): error: #20: identifier "LED_PINS" is undefined GPIO_SetBits(LED_PORT, LED_PINS); // 鍏抽棴LED Hardware\LED.c(63): error: #20: identifier "BREATH_ON" is undefined case BREATH_ON: Hardware\LED.c(67): error: #20: identifier "BREATH_FULL" is undefined case BREATH_FULL: Hardware\LED.c(75): warning: #223-D: function "HAL_GetTick" declared implicitly if(flowMode != LED_FLOW_OFF && (HAL_GetTick() - lastUpdate > 200)) { Hardware\LED.c(79): error: #20: identifier "LED_PINS" is undefined GPIO_SetBits(LED_PORT, LED_PINS); Hardware\LED.c(82): error: #20: identifier "LED_FLOW_FORWARD" is undefined if(flowMode == LED_FLOW_FORWARD) { Hardware\LED.c(93): error: #20: identifier "BREATH_ON" is undefined if(breathState == BREATH_ON && (HAL_GetTick() - lastUpdate > 10)) { Hardware\LED.c(93): warning: #223-D: function "HAL_GetTick" declared implicitly if(breathState == BREATH_ON && (HAL_GetTick() - lastUpdate > 10)) { Hardware\LED.c(34): warning: #177-D: variable "flowDir" was declared but never referenced static uint8_t flowDir = 0; // 0:宸︹啋鍙? 1:鍙斥啋宸? Hardware\LED.c: 4 warnings, 14 errors ".\Objects\Project.axf" - 43 Error(s), 7 Warning(s). Target not created.所有要修改的模块
07-12
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值