c - 源文件看不到其他 header 的定义

标签 c header-files c-preprocessor undeclared-identifier

我有一个自定义头文件(“strings.h”):

#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */
#include "sdkGlobal.h"

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */

#if !defined administration_H_
#define administration_H_

#define POS_STR_TITLE_OPERATIONS "somestr"

#endif

在我的其中一个源文件中:

#include "../inc/strings.h"

在我使用时的代码中:

    sdkShow (LINE3, 0, POS_STR_TITLE_OPERATIONS );

我得到错误:

src/main.c: In function 'postMainMenu':
src/main.c:190: error: 'POS_STR_TITLE_OPERATIONS ' undeclared (first use in this function)
src/main.c:190: error: (Each undeclared identifier is reported only once
src/main.c:190: error: for each function it appears in.)
make[1]: *** [src/main.o] Error 1
make: *** [all] Error 2

有什么想法吗?

最佳答案

守卫应该始终反射(reflect)要守卫的头文件的名称,因此它应该是“strings_H_”和“sdkGlobal_H_”

它适用于头文件有自己的依赖关系的更好的产品。例如“a.h”需要“length.h”,“b.h”也需要“length.h”,你可以保护“length.h”被计算一次。

关于c - 源文件看不到其他 header 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20994277/

相关文章:

c - 如何让 C 程序用作 Windows 申请表?

c++ - 使用前向引用

c++ - 我将如何处理大量的头文件?

类成员的 C++ header 和 .cc 文件问题

c - 如何在预处理器时间内计算数组大小?

C - sscanf 不忽略空白

c - 是否有允许不区分大小写的 C 编译器标志?

C - 结构变量是指针吗?

c - c 中条件编译#if 和#else(以及其他)的工作原理

c - C语言中#pragma和_Pragma()的区别