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

加入声明后报错消失。

相关推荐
DdddJMs__1359 分钟前
C语言 | Leetcode C语言题解之第458题可怜的小猪
c语言·leetcode·题解
凯子坚持 c1 小时前
C语言复习概要(四)
c语言·开发语言
武汉芯景科技有限公司2 小时前
关于武汉芯景科技有限公司的IIC电平转换芯片XJ9509开发指南(兼容PCa9509)
科技·stm32·单片机·嵌入式硬件
Bruce_Li_Q3 小时前
C语言贪吃蛇
c语言·开发语言
马浩同学3 小时前
【ESP32】Arduino开发 | Timer定时器+定时器闹钟例程
c语言·单片机·嵌入式硬件·mcu
Beginner_bml3 小时前
C语言---链表
c语言·数据结构
tomcoding3 小时前
自己写一个FTP客户端程序的过程
c语言·ftp客户端程序
闫铁娃3 小时前
二分解题的奇技淫巧都有哪些,你还不会吗?
c语言·数据结构·c++·算法·leetcode
千千道3 小时前
STM32 实现 UDP 广播通信
stm32·单片机·物联网·网络协议·udp
666xiaoniuzi4 小时前
深入理解 C 语言中的内存操作函数:memcpy、memmove、memset 和 memcmp
android·c语言·数据库