|
From: Steve P. <st...@ne...> - 2006-05-17 18:39:08
|
A cleaner approach IMHO would be. utils.h extern FILE *system_log_file; utils.c FILE *system_log_file; No messy cpp code. Steve Pribyl Steve AT NetFuel dot com Computer Infrastructure Practitioner Michael Gerdau wrote: >> I'm having a problem with a FILE pointer declared inside a header. >> When I try to link it, i got an "multiple definition" error. Here is a >> small test case: > > The probelm is you indeed _define_ it twice: > wherever you include utils.h the filepointer is defined. What you > actually want to do is define it once and _declare_ it everywhere > else. > > There are a couple of mechanisms to achieve that: > 1) Copy the line in utils.h into main.c and change utils.h as follows > extern FILE *system_log_file; > 2) Change utils.h as follows > #if defined(IN_MAIN) > FILE *system_log_file = NULL; > #else > extern FILE *system_log_file; > #endif > and insert > #define IN_MAIN > in main.c before including utils.h > > There are variations to this but you get the idea. > > HTH, best, > Michael |