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");
}

加入声明后报错消失。

相关推荐
FreakStudio2 天前
W55MH32L-EVB 上手测评:硬件 TCP/IP 加持的以太网单片机,MicroPython 零门槛开发
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy·电子计算机
LDR0067 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
✎ ﹏梦醒͜ღ҉繁华落℘7 天前
单片机基础知识---stm32单片机的优先级
stm32·单片机·mongodb
Luminous.7 天前
C语言--day30
c语言·开发语言
玖玥拾7 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
謓泽7 天前
C语言不是语法,是通往机器的地图。
c语言·开发语言
不会C语言的男孩7 天前
Linux 系统编程 · 第 8 章:进程基础
linux·c语言
zd8451015007 天前
RS485 总线详解
单片机·嵌入式硬件
2601_951643887 天前
C语言长文整理,关键字和数据类型
c语言·数据类型·关键字·嵌入式开发·格式化输出
m0_547486667 天前
《C#语言程序设计与实践》 全套PPT课件
c语言·c#·c语言程序设计