Miguel said:
I have a header file that I want to share among various files, and I use:
#ifndef UTIL_H_
#define UTIL_H_
file contents
But the compiler gives me an error
The compiler probably doesn't, but the linker might if you
have concrete definitions in the header.
For example, if you have a line such as
int a; /* notice, no extern */
in the header file, you are creating the int object 'a' with
external linkage rather than saying that one such object exists
elsewhere as you would by prefixing your definition with
'extern' and making it into a declaration.
Now, when you are including this header file multiple times
in the same translation unit, there is no problem because
of your include guards. However, if are attempting to link
two or more object files which were generated from separate
translation units, each of which having included it's own copy
of the header, then you will get a clash because the
external linkage object is defined more than once.
Alex