在a.h
中我有
#ifndef A_H
#define A_H 1
const int global_val = 10;
#endif
在a.c
中我有
#include "a.h"
int someFunc() {
return global_val;
}
但是编译器 (gcc) 在编译 a.c
时会抛出错误:'global_int' 未声明
。当我包含头文件时,它怎么可能是未声明的?
最佳答案
您应该有两个文件。
啊啊
#ifndef A_H
#define A_H 1
extern const int global_val;
#endif
和
空调
#include "A.h"
const int global_val = 10;
关于C 文件无法看到 #include 头文件中定义的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52066780/