2、You must never instantiate(实例化)things in header files, i.e. never define anything, just declare them.
You should put a single definition of each declared thing in one of the C files, and have extern
declarations in the shared header:
In mydata.h
:
struct Foo {
float baryness;
float baziness;
};
extern struct Foo TheFoo;
In one C file:
#include "mydata.h"
struct Foo TheFoo; //实例化
In other headers in the project:
#include "mydata.h"
printf("the baziness is %f right now\n", TheFoo.baziness);