This is a cut down example of a much larger project. You can see it here.
I have a header file containing the limits of the system time functions. Call it time_config.h.
#ifndef TIME_CONFIG_H
#define TIME_CONFIG_H
#define HAS_TIMEGM
#define SYSTEM_LOCALTIME_MAX 2147483647
#define SYSTEM_LOCALTIME_MIN -2147483648
#define SYSTEM_GMTIME_MAX 2147483647
#define SYSTEM_GMTIME_MIN -2147483648
const struct tm SYSTEM_MKTIME_MAX = { 7, 14, 19, 18, 0, 138, 0, 0, 0, 0, 0 };
const struct tm SYSTEM_MKTIME_MIN = { 52, 45, 12, 13, 11, 1, 0, 0, 0, 0, 0 };
#endif
Then there's a header file defining my time functions. Call it mytime.h. It includes time_config.h.
#ifndef MYTIME_H
#define MYTIME_H
#include "time_config.h"
#ifndef HAS_TIMEGM
time_t timegm(const struct tm*);
#endif
#endif
There's mytime.c which includes mytime.h and defines timegm(), if necessary.
I compile it into an object file...
gcc <a lot of warning flags> -I. -c -o mytime.o mytime.c
And link that into a test binary, t/year_limit.t.c also includes mytime.h.
gcc <a lot of warning flags> -I. mytime.o t/year_limit.t.c -o t/year_limit.t
Which errors out with:
ld: duplicate symbol _SYSTEM_MKTIME_MAX in /var/folders/eJ/eJzTVP7oG7GVsKYHJtMprE+++TI/-Tmp-//ccMe5DXb.o and mytime.o
collect2: ld returned 1 exit status
Because time_config.h is generated during the build process by a probe of the system, it would be very convenient to keep all the values together in one header file, or even multiple header files. Altering the .c file during the build process is more difficult.
It works fine without the structs. How do I declare the min/max date structs in a header file without causing this clash? Or am I compiling and linking incorrectly?
PS This is ANSI C89.