我想动态地在c中分配一个全局结构,但是某些东西使我的c文件无法找到对extern变量的引用。C外部结构指针动态分配
日志:
main.c:18: undefined reference to `gate_array'
extern.h
#ifndef EXTERN_H_
#define EXTERN_H_
typedef struct gate_struct {
int out;
} gate;
extern gate *gate_array;
#endif /* EXTERN_H_ */
的main.c:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "extern.h"
int main(int argc, char *argv[]){
gate_array = (gate*) malloc (2* sizeof(gate));
return 0;
}
谢谢!
哪里是'gate_array'声明? – triclosan