keil报错:main.c(99): error: #20: identifier “xxx“ is undefined

报错如下:

main.c(116): main.c(116): error: #20: identifier "g_pol_par_linear" is undefined

main.c(99): error: #20: identifier "g_motor_sta_linear" is undefined

main

cs 复制代码
#include "Interpolation_Linear.h"     //Interpolation_Linear.c里定义了g_pol_par_linear

int main(void)
{
	g_pol_par_linear.moving_mode = 1;
    while(g_motor_sta_linear);	
	printf("圆弧插补\r\n");
}

Interpolation_Linear.c

cs 复制代码
//结构体
inter_pol_def g_pol_par_linear= {0};   /* 直线插补参数值 */


//枚举
__IO st_motor_status_def  g_motor_sta_linear = STATE_STOP_linear;     /* 步进电机运动状态 */

我认为在主函数里引用了"Interpolation_Linear"的头文件,就包含了里面定义的变量。

但是会报错。

解决办法:在主函数加extern声明。

cs 复制代码
#include "Interpolation_Linear.h"     //Interpolation_Linear.c里定义了g_pol_par_linear

extern inter_pol_def g_pol_par_linear;					//直线插补模式
extern st_motor_status_def  g_motor_sta_linear;			//直线插补	运动模式

int main(void)
{
	g_pol_par_linear.moving_mode = 1;
    while(g_motor_sta_linear);
	printf("圆弧插补\r\n");
}

加入声明后报错消失。

相关推荐
RuoZoe8 天前
重塑WPF辉煌?基于DirectX 12的现代.NET UI框架Jalium
c语言
祈安_11 天前
C语言内存函数
c语言·后端
norlan_jame13 天前
C-PHY与D-PHY差异
c语言·开发语言
czy878747513 天前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
悠哉悠哉愿意13 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
m0_5312371713 天前
C语言-数组练习进阶
c语言·开发语言·算法
Lester_110113 天前
STM32霍尔传感器输入口设置为复用功能输入口时,还能用GPIO函数直接读取IO的状态吗
stm32·单片机·嵌入式硬件·电机控制
三佛科技-1873661339713 天前
120W小体积碳化硅电源方案(LP8841SC极简方案12V10A/24V5A输出)
单片机·嵌入式硬件
z203483152013 天前
STM32F103系列单片机定时器介绍(二)
stm32·单片机·嵌入式硬件
Z9fish13 天前
sse哈工大C语言编程练习23
c语言·数据结构·算法