'xxx' undeclared (first use in this function)

1  加头文件!

     2   添加修改声明!

我使用的场景:在a.h文件里声明一个枚举xxx,该枚举在a.c中使用到了这个枚举,同时有个b.h和b.c两个文件,其中b.c也是用到了这个枚举,b.c包含了a.h和b.h。在b.c中封装了对外接口,若其他文件c.c访问到这个接口,并应用到这个枚举,只包含了b.h的话,就会报这个错误,当然把a.h也包含上就不会出现这个错误。

举个例子:比如说有a.h,b.h,a.c,b.c,c.c五个文件,a文件是比较底层的接口实现,b文件对a文件的接口进行了封装,使其更通用一点了,然后c.c去使用这些通用接口。

a.h声明如下:

typedef enum enTest
{member0,member1,member2,
}test_e;extern int add(int a, int b);

a.c

#include <stdio.h>
#include "a.h"int add(int a, int b)
{return a + b + member2;
}int main()
{return 0;
}

b.h

extern int ADD(int a, int b, test_e enM);

b.c

#include <stdio.h>
#include "a.h"
#include "b.h"int ADD(int a, int b, test_e enM)
{int ret = add(a, b);return ret + enM;
}

c.c

#include <stdio.h>
#include "b.h"int main()
{int ret = 0;int a = 3;int b = 5;ret = ADD(a, b, member2);printf("%d\n", ret);return 0
}

c.c中使用到了a.h中申明的枚举,但没有包含a.h,所以会报错undeclared (first use in this function)。此时可以添加a.h即可解决问题。但是其他任何文件使用b.h中的接口和a.h中的枚举时,都要包含这两个头文件,会比较麻烦。

解决方法是:在b.h中也声明一下这个枚举,但名字不能重复,且位置相对应不动,这样c.c中使用只需要包含b.h文件即可。

undeclared (first use in this function)相关推荐

  1. 【c语言 gcc9.1.0环境下编译报错】error: ‘true’ undeclared (first use in this function)

    问题 网上验证一个单链表是否有环的c语言demo,放到gcc9.1.0的环境下编译,发现编译报错: error: 'true' undeclared (first use in this functi ...

  2. Android之ndk-build出现c:28:51: error: ‘get_string‘ undeclared here (not in a function)解决办法

    1 problem ndk-build error: 'get_string' undeclared here (not in a function) 2 resolve jstring get_st ...

  3. 安装nginx时关系依赖库openssl.lib时,出现:error: 'NR_syscalls' undeclared (first use in this function)

    安装nginx时关系依赖库openssl.lib时,出现:error: 'NR_syscalls' undeclared (first use in this function) 解决方案:根据arc ...

  4. 编译内核遇到:error: ‘ovl_v1_fs_type’ undeclared (first use in this function)错误

    如遇到如下错误: fs/overlayfs/super.c: In function 'ovl_init': fs/overlayfs/super.c:1331:30: error: 'ovl_v1_ ...

  5. /phalcon.zep.c:130892: error: ‘ZEND_FE_END’ undeclared here (not in a function)

    /phalcon.zep.c:130892: error: 'ZEND_FE_END' undeclared here (not in a function) 因为centos6.5上的最新php版本 ...

  6. error: 'FILE' undeclared (first use in this function)

    error: 'FILE' undeclared (first use in this function) 今天在打trace调试底层代码的时候添加: {FILE* fp = fopen(" ...

  7. C编译时`true' undeclared (first use in this function)

    在编译C语言时有时会遇到这样的错误提示: `true' undeclared (first use in this function) or `false' undeclared (first use ...

  8. Error ‘false‘ undeclared (first use in this function)解决

    Error: 'false' undeclared (first use in this function)解决 在用DEVC++敲代码时,对如下程序报错 bool ok(int t){//判定第t个 ...

  9. error: ‘CLOCK_MONOTONIC‘ undeclared (first use in this function)

    错误信息: /home/xx/test/main.c: In function 'main': /home/xx/test/main.c:37:21: error: storage size of ' ...

最新文章

  1. python多线程_【python多线程02】各种线程锁
  2. 故事工程学:人工智能和程序化叙事生成
  3. python学习实例(4)
  4. java简单的文本编辑器_采用java语言如何建立一个简单的文本编辑器
  5. 【c语言】定义一个指针数组,指向5个不同的char型数组
  6. Redis学习总结(6)——Redis 高级特性与案例学习
  7. 飞步神速!何晓飞团队完成无人车深度学习芯片流片,算力创国内新高
  8. NoSQL数据库教程
  9. 西门子S7-1200PLC通过脉冲+方向控制台达ASDA-B2伺服的具体方法步骤(图文)
  10. 三菱PLC编程口通信上位机端报文和java示范代码
  11. 马斯克联名2000多AI专家誓言禁绝杀人机器人!发起人泰格马克将亲临AI World2018...
  12. 有哪些令人骄傲的国产软件或应用?这5款你一定不知道!
  13. bt tracker服务器 相关内容
  14. 一个软件完整的开发流程介绍
  15. 强化学习6——policy gradient的优化( Use temporal causality,Baseline and Critic)
  16. DICOM的理解与学习2
  17. 实验吧WEB CTF 猫抓老鼠 全网最简单易懂的解题方法
  18. Spring Boot使用@RepeatSubmit 防止重复提交
  19. Office 2007兼容工具包
  20. 驱动机架的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告

热门文章

  1. Matlab同一figure中使用多种色图
  2. IDEA安装中文语言包
  3. C/C++ 信号处理 Signal
  4. mysql初始化失败解决方法
  5. 25个最恶意的病毒网站 千万不要点击浏览!
  6. 公司×××访问建立之三核心交换机Huawei Quidway S6502的设置
  7. 飞鸽传书网因存在低俗内容致网友的道歉信
  8. IDBLK_TIMING.dll群联量产数据库文件合集
  9. java guice_如何在Guice中进行需要注入实例的动态绑定?
  10. php 无法添加ico 图标,PHP 保存到桌面的代码,怎么加ICO图标跟乱码问题呢