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

加入声明后报错消失。

相关推荐
2601_966494726 分钟前
C语言是什么
c语言·rust·linux内核·内存管理·系统编程
老师我太想进步了20269 分钟前
【数据结构-16】链式二叉树在线OJ题
c语言·数据结构·算法
程序员大阳27 分钟前
副队长C语言数据结构教程(4)--双向链表
c语言·数据结构·链表·双向链表
AndreaYYmm1 小时前
一张 1KB 的表算出整个报文的校验和:CRC 查表法、端序陷阱与一个反直觉的性能结论
c语言·架构
AndreaYYmm1 小时前
任务 A 的配置消息,在任务 B 起来之前就发了:两阶段启动屏障
c语言·架构
老花眼猫1 小时前
C语言绘图方法:(22)高斯面旋转
c语言·经验分享·青少年编程·课程设计
小李不想当小白2 小时前
HAL库之中断(STM32 HAL库学习笔记)
笔记·stm32·单片机·嵌入式硬件·学习·嵌入式
都在酒里3 小时前
STM32G431 + FreeRTOS CAN 通信实战:FDCAN 收发、过滤与 Bus-Off 恢复
stm32·单片机·嵌入式硬件
Navigator_Z6 小时前
LeetCode //C - 1326. Minimum Number of Taps to Open to Water a Garden
c语言·算法·leetcode
..Dauntless..6 小时前
【stm32】中断(三)——NVIC
stm32·单片机·嵌入式硬件