实际已经定义却出现 error: #20: identifier “xxx“ is undefined 的错误

该博客基于MDK5.26的C环境,针对“已经定义了xxx,但却报没定义的错”这一问题展开。分析了定义多个头文件时出现顺序逻辑错误的原因,即相对于a.h文件,在定义ITEM结构体前调用了b.h,而b.h里有对Item_t类型变量的定义。给出解决办法,在大工程中头文件按需包含。

原文:https://blog.youkuaiyun.com/wuyuzun/article/details/97803640

前言

  1. 本博文基于MDK5.26的C环境编写,不过跟芯片没关系,是软件调试出现的问题;
  2. 本博文并一定适合其他原因引起的未定义错误,仅适合“已经定义了xxx,但却报没定义的错”这种情况;
  3. 如有不足之处,还请多多指教;

迷之错误:error: #20: identifier “xxx” is undefined

实际上我是定义了xxx的;但是编译器却一直报错;
故事是这样的:
我定义了a.h,b.h,c.h。其中a.h和b.h都是子功能头文件,而c.h是包含所有项目头文件的集合体,比如数据类型,当然也包含a.h和b.h;关系看下面代码;

/*  c.h  */
#ifndef C_H
#define C_H

#include "Type.h"
#include "a.h"
#include "b.h"
#include "x.h"
#include "xx.h"
#include "xxx.h"

#endif /* C_H */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
/*  a.h  */
#include "c.h"      //为了让头文件看起来更简单,我为每一个子功能头文件都包含了c.h,这将是后来引起错误的地方;

typedef  struct  ITEM
{
	//各成员				
}Item_t;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
/*  b.h  */
#include "c.h"     

struct  BLOCK
{
	Item_t  	Item1;       // 这里我引用了a.h中的Item_t类型,并定义了变量;这里就是报错的地方;
	//其他成员;	
				
}Block;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

这种情况下就出了问题,那么问题在哪儿哪?
在b.h中的Item_t Item1; ** ,这个地方就是报错的地方;显示error: #20: identifier “Item_t” is undefined,顺着这儿往上看的,这个问题就出在了a.h里的这个#include “c.h” **;对于a.h来说,调用的 **#include “c.h”**可以展开为:

/*  a.h  */

#include "Type.h"
#include "a.h"
#include "b.h"     
#include "x.h"
#include "xx.h"
#include "xxx.h"


typedef struct  ITEM
{
	//各成员				
}Item_t;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

所以错误的地方是:相对于a.h文件来说,在定义ITEM结构体之前就已经调用了b.h,而b.h里又有对Item_t类型变量的定义,所以就出顺序逻辑错误;

解决办法

在大工程中尽量避免在头文件中使用总头文件;所以这里就在a.h和b.h中去掉包含的c.h文件,需要什么头文件就用什么头文件;所以修改完之后是:

/*  a.h  */
#include "Type.h"     
#include "x.h"
#include "xx.h"
#include "xxx.h"

typedef  struct  ITEM
{
	//各成员				
}Item_t;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
/*  b.h  */
#include "a.h"
#include "x.h"
#include "xx.h"
#include "xxx.h"

struct  BLOCK
{
	Item_t  	Item1;    
	//其他成员;	
				
}Block;
*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'E:\stm32\ARM\ARMCC\Bin' Build target 'BreathingLightProMax' compiling i2c.c... ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Inc/i2c.h(35): error: #20: identifier "I2C_HandleTypeDef" is undefined extern I2C_HandleTypeDef hi2c1; ../Core/Src/i2c.c(27): error: #20: identifier "I2C_HandleTypeDef" is undefined I2C_HandleTypeDef hi2c1; ../Core/Src/i2c.c(40): error: #20: identifier "I2C1" is undefined hi2c1.Instance = I2C1; ../Core/Src/i2c.c(42): error: #20: identifier "I2C_DUTYCYCLE_2" is undefined hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; ../Core/Src/i2c.c(44): error: #20: identifier "I2C_ADDRESSINGMODE_7BIT" is undefined hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; ../Core/Src/i2c.c(45): error: #20: identifier "I2C_DUALADDRESS_DISABLE" is undefined hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; ../Core/Src/i2c.c(47): error: #20: identifier "I2C_GENERALCALL_DISABLE" is undefined hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; ../Core/Src/i2c.c(48): error: #20: identifier "I2C_NOSTRETCH_DISABLE" is undefined hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; ../Core/Src/i2c.c(49): warning: #223-D: function "HAL_I2C_Init" declared implicitly if (HAL_I2C_Init(&hi2c1) != HAL_OK) ../Core/Src/i2c.c(49): error: #20: identifier "HAL_OK" is undefined if (HAL_I2C_Init(&hi2c1) != HAL_OK) ../Core/Src/i2c.c(51): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); ../Core/Src/i2c.c(59): error: #20: identifier "I2C_HandleTypeDef" is undefined void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) ../Core/Src/i2c.c(62): error: #20: identifier "GPIO_InitTypeDef" is undefined GPIO_InitTypeDef GPIO_InitStruct = {0}; ../Core/Src/i2c.c(63): error: #20: identifier "I2C1" is undefined if(i2cHandle->Instance==I2C1) ../Core/Src/i2c.c(69): warning: #223-D: function "__HAL_RCC_GPIOB_CLK_ENABLE" declared implicitly __HAL_RCC_GPIOB_CLK_ENABLE(); ../Core/Src/i2c.c(74): error: #20: identifier "GPIO_PIN_6" is undefined GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; ../Core/Src/i2c.c(74): error: #20: identifier "GPIO_PIN_7" is undefined GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; ../Core/Src/i2c.c(75): error: #20: identifier "GPIO_MODE_AF_OD" is undefined GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; ../Core/Src/i2c.c(76): error: #20: identifier "GPIO_SPEED_FREQ_HIGH" is undefined GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; ../Core/Src/i2c.c(77): warning: #223-D: function "HAL_GPIO_Init" declared implicitly HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); ../Core/Src/i2c.c(77): error: #20: identifier "GPIOB" is undefined HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); ../Core/Src/i2c.c(80): warning: #223-D: function "__HAL_RCC_I2C1_CLK_ENABLE" declared implicitly __HAL_RCC_I2C1_CLK_ENABLE(); ../Core/Src/i2c.c(87): error: #20: identifier "I2C_HandleTypeDef" is undefined void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle) ../Core/Src/i2c.c(90): error: #20: identifier "I2C1" is undefined if(i2cHandle->Instance==I2C1) ../Core/Src/i2c.c(96): warning: #223-D: function "__HAL_RCC_I2C1_CLK_DISABLE" declared implicitly __HAL_RCC_I2C1_CLK_DISABLE(); ../Core/Src/i2c.c(102): warning: #223-D: function "HAL_GPIO_DeInit" declared implicitly HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6); ../Core/Src/i2c.c(102): error: #20: identifier "GPIOB" is undefined HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6); ../Core/Src/i2c.c(102): error: #20: identifier "GPIO_PIN_6" is undefined HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6); ../Core/Src/i2c.c(104): error: #20: identifier "GPIO_PIN_7" is undefined HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7); ../Core/Src/i2c.c: 7 warnings, 23 errors compiling stm32f1xx_hal_msp.c... ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Src/stm32f1xx_hal_msp.c(70): warning: #223-D: function "__HAL_RCC_AFIO_CLK_ENABLE" declared implicitly __HAL_RCC_AFIO_CLK_ENABLE(); ../Core/Src/stm32f1xx_hal_msp.c(71): warning: #223-D: function "__HAL_RCC_PWR_CLK_ENABLE" declared implicitly __HAL_RCC_PWR_CLK_ENABLE(); ../Core/Src/stm32f1xx_hal_msp.c(77): warning: #223-D: function "__HAL_AFIO_REMAP_SWJ_NOJTAG" declared implicitly __HAL_AFIO_REMAP_SWJ_NOJTAG(); ../Core/Src/stm32f1xx_hal_msp.c: 3 warnings, 1 error compiling stm32f1xx_it.c... ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Src/stm32f1xx_it.c(58): error: #20: identifier "UART_HandleTypeDef" is undefined extern UART_HandleTypeDef huart3; ../Core/Src/stm32f1xx_it.c(188): warning: #223-D: function "HAL_IncTick" declared implicitly HAL_IncTick(); ../Core/Src/stm32f1xx_it.c(209): warning: #223-D: function "HAL_UART_IRQHandler" declared implicitly HAL_UART_IRQHandler(&huart3); ../Core/Src/stm32f1xx_it.c: 2 warnings, 2 errors compiling usart.c... ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Inc/usart.h(37): error: #20: identifier "uint16_t" is undefined extern uint16_t current_freq; ../Core/Inc/usart.h(38): error: #20: identifier "uint16_t" is undefined extern uint16_t current_duty; ../Core/Inc/usart.h(41): error: #20: identifier "UART_HandleTypeDef" is undefined extern UART_HandleTypeDef huart3; ../Core/Inc/usart.h(45): error: #20: identifier "uint32_t" is undefined void VOFA_Send(float *data, uint32_t count); ../Core/Src/usart.c(24): error: #20: identifier "uint8_t" is undefined const uint8_t firewave_head[FIREWAVE_HEAD_LEN] = {0xAA, 0x07, 0x00, 0x00}; ../Core/Src/usart.c(25): error: #20: identifier "uint8_t" is undefined const uint8_t firewave_tail[FIREWAVE_TAIL_LEN] = {0x00, 0x00, 0x07, 0xAA}; ../Core/Src/usart.c(30): error: #20: identifier "UART_HandleTypeDef" is undefined UART_HandleTypeDef huart3; ../Core/Src/usart.c(44): error: #20: identifier "USART3" is undefined huart3.Instance = USART3; ../Core/Src/usart.c(46): error: #20: identifier "UART_WORDLENGTH_8B" is undefined huart3.Init.WordLength = UART_WORDLENGTH_8B; ../Core/Src/usart.c(47): error: #20: identifier "UART_STOPBITS_1" is undefined huart3.Init.StopBits = UART_STOPBITS_1; ../Core/Src/usart.c(48): error: #20: identifier "UART_PARITY_NONE" is undefined huart3.Init.Parity = UART_PARITY_NONE; ../Core/Src/usart.c(49): error: #20: identifier "UART_MODE_TX_RX" is undefined huart3.Init.Mode = UART_MODE_TX_RX; ../Core/Src/usart.c(50): error: #20: identifier "UART_HWCONTROL_NONE" is undefined huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; ../Core/Src/usart.c(51): error: #20: identifier "UART_OVERSAMPLING_16" is undefined huart3.Init.OverSampling = UART_OVERSAMPLING_16; ../Core/Src/usart.c(52): warning: #223-D: function "HAL_UART_Init" declared implicitly if (HAL_UART_Init(&huart3) != HAL_OK) ../Core/Src/usart.c(52): error: #20: identifier "HAL_OK" is undefined if (HAL_UART_Init(&huart3) != HAL_OK) ../Core/Src/usart.c(54): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); ../Core/Src/usart.c(62): error: #20: identifier "UART_HandleTypeDef" is undefined void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) ../Core/Src/usart.c(65): error: #20: identifier "GPIO_InitTypeDef" is undefined GPIO_InitTypeDef GPIO_InitStruct = {0}; ../Core/Src/usart.c(66): error: #20: identifier "USART3" is undefined if(uartHandle->Instance==USART3) ../Core/Src/usart.c(72): warning: #223-D: function "__HAL_RCC_USART3_CLK_ENABLE" declared implicitly __HAL_RCC_USART3_CLK_ENABLE(); ../Core/Src/usart.c(74): warning: #223-D: function "__HAL_RCC_GPIOB_CLK_ENABLE" declared implicitly __HAL_RCC_GPIOB_CLK_ENABLE(); ../Core/Src/usart.c(79): error: #20: identifier "GPIO_PIN_10" is undefined GPIO_InitStruct.Pin = GPIO_PIN_10; ../Core/Src/usart.c(80): error: #20: identifier "GPIO_MODE_AF_PP" is undefined GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; ../Core/Src/usart.c(81): error: #20: identifier "GPIO_SPEED_FREQ_HIGH" is undefined GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; ../Core/Src/usart.c(82): warning: #223-D: function "HAL_GPIO_Init" declared implicitly HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); ../Core/Src/usart.c(82): error: #20: identifier "GPIOB" is undefined HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); ../Core/Src/usart.c(84): error: #20: identifier "GPIO_PIN_11" is undefined GPIO_InitStruct.Pin = GPIO_PIN_11; ../Core/Src/usart.c(85): error: #20: identifier "GPIO_MODE_INPUT" is undefined GPIO_InitStruct.Mode = GPIO_MODE_INPUT; ../Core/Src/usart.c(86): error: #20: identifier "GPIO_NOPULL" is undefined GPIO_InitStruct.Pull = GPIO_NOPULL; ../Core/Src/usart.c(90): warning: #223-D: function "HAL_NVIC_SetPriority" declared implicitly HAL_NVIC_SetPriority(USART3_IRQn, 0, 0); ../Core/Src/usart.c(90): error: #20: identifier "USART3_IRQn" is undefined HAL_NVIC_SetPriority(USART3_IRQn, 0, 0); ../Core/Src/usart.c(91): warning: #223-D: function "HAL_NVIC_EnableIRQ" declared implicitly HAL_NVIC_EnableIRQ(USART3_IRQn); ../Core/Src/usart.c(98): error: #20: identifier "UART_HandleTypeDef" is undefined void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) ../Core/Src/usart.c(101): error: #20: identifier "USART3" is undefined if(uartHandle->Instance==USART3) ../Core/Src/usart.c(107): warning: #223-D: function "__HAL_RCC_USART3_CLK_DISABLE" declared implicitly __HAL_RCC_USART3_CLK_DISABLE(); ../Core/Src/usart.c(113): warning: #223-D: function "HAL_GPIO_DeInit" declared implicitly HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11); ../Core/Src/usart.c(113): error: #20: identifier "GPIOB" is undefined HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11); ../Core/Src/usart.c: 9 warnings, 30 errors compiling tim.c... ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Inc/tim.h(32): error: #20: identifier "uint16_t" is undefined extern uint16_t current_freq; ../Core/Inc/tim.h(33): error: #20: identifier "uint16_t" is undefined extern uint16_t current_duty; ../Core/Inc/tim.h(36): error: #20: identifier "TIM_HandleTypeDef" is undefined extern TIM_HandleTypeDef htim1; ../Core/Inc/tim.h(38): error: #20: identifier "TIM_HandleTypeDef" is undefined extern TIM_HandleTypeDef htim2; ../Core/Inc/tim.h(40): error: #20: identifier "TIM_HandleTypeDef" is undefined extern TIM_HandleTypeDef htim3; ../Core/Inc/tim.h(42): error: #20: identifier "TIM_HandleTypeDef" is undefined extern TIM_HandleTypeDef htim4; ../Core/Inc/tim.h(53): error: #20: identifier "TIM_HandleTypeDef" is undefined void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); ../Core/Src/tim.c(27): error: #20: identifier "TIM_HandleTypeDef" is undefined TIM_HandleTypeDef htim1; ../Core/Src/tim.c(28): error: #20: identifier "TIM_HandleTypeDef" is undefined TIM_HandleTypeDef htim2; ../Core/Src/tim.c(29): error: #20: identifier "TIM_HandleTypeDef" is undefined TIM_HandleTypeDef htim3; ../Core/Src/tim.c(30): error: #20: identifier "TIM_HandleTypeDef" is undefined TIM_HandleTypeDef htim4; ../Core/Src/tim.c(40): error: #20: identifier "TIM_ClockConfigTypeDef" is undefined TIM_ClockConfigTypeDef sClockSourceConfig = {0}; ../Core/Src/tim.c(41): error: #20: identifier "TIM_MasterConfigTypeDef" is undefined TIM_MasterConfigTypeDef sMasterConfig = {0}; ../Core/Src/tim.c(42): error: #20: identifier "TIM_OC_InitTypeDef" is undefined TIM_OC_InitTypeDef sConfigOC = {0}; ../Core/Src/tim.c(43): error: #20: identifier "TIM_BreakDeadTimeConfigTypeDef" is undefined TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; ../Core/Src/tim.c(48): error: #20: identifier "TIM1" is undefined htim1.Instance = TIM1; ../Core/Src/tim.c(50): error: #20: identifier "TIM_COUNTERMODE_UP" is undefined htim1.Init.CounterMode = TIM_COUNTERMODE_UP; ../Core/Src/tim.c(52): error: #20: identifier "TIM_CLOCKDIVISION_DIV1" is undefined htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; ../Core/Src/tim.c(54): error: #20: identifier "TIM_AUTORELOAD_PRELOAD_ENABLE" is undefined htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; ../Core/Src/tim.c(55): warning: #223-D: function "HAL_TIM_Base_Init" declared implicitly if (HAL_TIM_Base_Init(&htim1) != HAL_OK) ../Core/Src/tim.c(55): error: #20: identifier "HAL_OK" is undefined if (HAL_TIM_Base_Init(&htim1) != HAL_OK) ../Core/Src/tim.c(57): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); ../Core/Src/tim.c(59): error: #20: identifier "TIM_CLOCKSOURCE_INTERNAL" is undefined sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; ../Core/Src/tim.c(60): warning: #223-D: function "HAL_TIM_ConfigClockSource" declared implicitly if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) ../Core/Src/tim.c(60): error: #20: identifier "HAL_OK" is undefined if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) ../Core/Src/tim.c(62): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); ../Core/Src/tim.c(64): warning: #223-D: function "HAL_TIM_PWM_Init" declared implicitly if (HAL_TIM_PWM_Init(&htim1) != HAL_OK) ../Core/Src/tim.c(64): error: #20: identifier "HAL_OK" is undefined if (HAL_TIM_PWM_Init(&htim1) != HAL_OK) ../Core/Src/tim.c(66): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); ../Core/Src/tim.c(68): warning: #223-D: function "HAL_TIM_OC_Init" declared implicitly if (HAL_TIM_OC_Init(&htim1) != HAL_OK) ../Core/Src/tim.c(68): error: #20: identifier "HAL_OK" is undefined if (HAL_TIM_OC_Init(&htim1) != HAL_OK) ../Core/Src/tim.c(70): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); ../Core/Src/tim.c(72): error: #20: identifier "TIM_TRGO_RESET" is undefined sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; ../Core/Src/tim.c(73): error: #20: identifier "TIM_MASTERSLAVEMODE_DISABLE" is undefined sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; ../Core/Src/tim.c(74): warning: #223-D: function "HAL_TIMEx_MasterConfigSynchronization" declared implicitly if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) ../Core/Src/tim.c(74): error: #20: identifier "HAL_OK" is undefined if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) ../Core/Src/tim.c(76): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); ../Core/Src/tim.c(78): error: #20: identifier "TIM_OCMODE_PWM1" is undefined sConfigOC.OCMode = TIM_OCMODE_PWM1; ../Core/Src/tim.c(80): error: #20: identifier "TIM_OCPOLARITY_HIGH" is undefined sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; ../Core/Src/tim.c: 10 warnings, 30 errors compiling gpio.c... ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Src/gpio.c(45): error: #20: identifier "GPIO_InitTypeDef" is undefined GPIO_InitTypeDef GPIO_InitStruct = {0}; ../Core/Src/gpio.c(48): warning: #223-D: function "__HAL_RCC_GPIOD_CLK_ENABLE" declared implicitly __HAL_RCC_GPIOD_CLK_ENABLE(); ../Core/Src/gpio.c(49): warning: #223-D: function "__HAL_RCC_GPIOA_CLK_ENABLE" declared implicitly __HAL_RCC_GPIOA_CLK_ENABLE(); ../Core/Src/gpio.c(50): warning: #223-D: function "__HAL_RCC_GPIOB_CLK_ENABLE" declared implicitly __HAL_RCC_GPIOB_CLK_ENABLE(); ../Core/Src/gpio.c(54): error: #20: identifier "K3_Pin" is undefined GPIO_InitStruct.Pin = K3_Pin|K4_Pin|K5_Pin|K6_Pin ../Core/Src/gpio.c(54): error: #20: identifier "K4_Pin" is undefined GPIO_InitStruct.Pin = K3_Pin|K4_Pin|K5_Pin|K6_Pin ../Core/Src/gpio.c(54): error: #20: identifier "K5_Pin" is undefined GPIO_InitStruct.Pin = K3_Pin|K4_Pin|K5_Pin|K6_Pin ../Core/Src/gpio.c(54): error: #20: identifier "K6_Pin" is undefined GPIO_InitStruct.Pin = K3_Pin|K4_Pin|K5_Pin|K6_Pin ../Core/Src/gpio.c(55): error: #20: identifier "K1_Pin" is undefined |K1_Pin|K2_Pin; ../Core/Src/gpio.c(55): error: #20: identifier "K2_Pin" is undefined |K1_Pin|K2_Pin; ../Core/Src/gpio.c(56): error: #20: identifier "GPIO_MODE_INPUT" is undefined GPIO_InitStruct.Mode = GPIO_MODE_INPUT; ../Core/Src/gpio.c(57): error: #20: identifier "GPIO_PULLUP" is undefined GPIO_InitStruct.Pull = GPIO_PULLUP; ../Core/Src/gpio.c(58): warning: #223-D: function "HAL_GPIO_Init" declared implicitly HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); ../Core/Src/gpio.c(58): error: #20: identifier "GPIOA" is undefined HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); ../Core/Src/gpio.c: 4 warnings, 11 errors compiling key.c... key.h(16): warning: #1-D: last line of file ends without a newline #endif ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H key.c(96): error: #20: identifier "target_frequency" is undefined target_frequency = (float)current_freq; key.c(97): error: #20: identifier "target_duty_cycle" is undefined target_duty_cycle = (float)current_duty; key.c: 1 warning, 4 errors compiling main.c... ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Src/main.c(104): error: #20: identifier "htim1" is undefined uint16_t arr1 = _HAL_TIM_GET_AUTORELOAD(&htim1); ../Core/Src/main.c(110): error: #20: identifier "htim2" is undefined uint16_t arr2 = _HAL_TIM_GET_AUTORELOAD(&htim2); ../Core/Src/main.c(116): error: #20: identifier "htim3" is undefined uint16_t arr3 = _HAL_TIM_GET_AUTORELOAD(&htim3); ../Core/Src/main.c(122): error: #20: identifier "htim4" is undefined uint16_t arr4 = _HAL_TIM_GET_AUTORELOAD(&htim4); ../Core/Src/main.c(157): error: #20: identifier "htim1" is undefined htim1.Instance->ARR = arr; ../Core/Src/main.c(163): error: #20: identifier "htim1" is undefined htim1.Instance->CCR2 = htim1.Instance->ARR * current_duty / 100; ../Core/Src/main.c(192): error: #20: identifier "huart3" is undefined HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xffff); ../Core/Src/main.c(226): warning: #223-D: function "MX_GPIO_Init" declared implicitly MX_GPIO_Init(); ../Core/Src/main.c(227): warning: #223-D: function "MX_TIM2_Init" declared implicitly MX_TIM2_Init(); ../Core/Src/main.c(228): warning: #223-D: function "MX_TIM1_Init" declared implicitly MX_TIM1_Init(); ../Core/Src/main.c(229): warning: #223-D: function "MX_TIM3_Init" declared implicitly MX_TIM3_Init(); ../Core/Src/main.c(230): warning: #223-D: function "MX_TIM4_Init" declared implicitly MX_TIM4_Init(); ../Core/Src/main.c(231): warning: #223-D: function "MX_I2C1_Init" declared implicitly MX_I2C1_Init(); ../Core/Src/main.c(232): warning: #223-D: function "MX_USART3_UART_Init" declared implicitly MX_USART3_UART_Init(); ../Core/Src/main.c(234): error: #20: identifier "htim1" is undefined HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1); ../Core/Src/main.c(235): error: #20: identifier "htim2" is undefined HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_1); ../Core/Src/main.c(236): error: #20: identifier "htim3" is undefined HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_1); ../Core/Src/main.c(237): error: #20: identifier "htim4" is undefined HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_3); ../Core/Src/main.c(347): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); ../Core/Src/main.c(361): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); ../Core/Src/main.c(373): error: #159: declaration is incompatible with previous "Error_Handler" (declared at line 347) void Error_Handler(void) ../Core/Src/main.c(101): warning: #177-D: function "BreathingLight" was declared but never referenced static void BreathingLight(void){ ../Core/Src/main.c: 10 warnings, 17 errors compiling sdd1306.c... ../Core/Inc/main.h(22): error: #37: the #endif for this directive is missing #ifndef __MAIN_H ../Core/Inc/i2c.h(35): error: #20: identifier "I2C_HandleTypeDef" is undefined extern I2C_HandleTypeDef hi2c1; ..\Core\Src\sdd1306.c(257): warning: #177-D: variable "x_start_cycle" was declared but never referenced int x_start_cycle = current_x; ..\Core\Src\sdd1306.c(13): warning: #177-D: variable "wave_x" was declared but never referenced static uint8_t wave_x = 0; // 波形当前的X坐标 ..\Core\Src\sdd1306.c: 2 warnings, 2 errors "BreathingLightProMax\BreathingLightProMax.axf" - 120 Error(s), 48 Warning(s). Target not created.
最新发布
11-27
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值