我有一个自定义头文件(“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/