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

加入声明后报错消失。

相关推荐
Mr-pn-junction3 小时前
clk_gate
单片机·嵌入式硬件·fpga开发
无相求码11 小时前
【C语言】字符串的本质是什么,为什么 strlen 会读到野内存
c语言·开发语言
李永奉11 小时前
杰理可视化SDK开发-【BUG】配置“TWS两边同时按消息使能”功能后,按键单击功能无效失灵
开发语言·单片机·嵌入式硬件·物联网·bug
执迷不悟82311 小时前
51单片机--中断/定时/PWM
单片机·嵌入式硬件·51单片机
LuminousCPP12 小时前
C 语言集中实践全记录:顺序表 + 单链表原理实现与通讯录项目实战【附可运行源码】
c语言·开发语言·数据结构·经验分享·笔记
SuperByteMaster12 小时前
__set_MSP 和__set_MSPLIM 接口区别
c语言
A小调的码农13 小时前
OPENOCD+MSYS+VSCODE:从“灯不亮“到“终于亮了“
ide·vscode·stm32·单片机·编辑器
CS创新实验室14 小时前
NumPy数组的C风格和Fortran风格
c语言·开发语言·numpy
Dlrb121114 小时前
单片机通信协议---串口及串口通信
单片机·嵌入式硬件·串口·uart·modbus·波特率·主机从机
嵌入式-老费15 小时前
esp32开发与应用(用好ttl转485模块)
stm32·单片机·嵌入式硬件