|
From: Oberdan L. M. <obe...@gm...> - 2006-05-17 18:13:37
|
Hello all,
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:
utils.h :
#ifndef __UTILS_H__
#define __UTILS_H__
FILE *system_log_file =3D NULL;
#endif
-------------
utils.c (it is empty, has only the includes):
#include <stdio.h>
#include "utils.h"
-------------
main.c :
#include <stdio.h>
#include "utils.h"
int main( int argc , char *argv[] )
{
return(0);
};
----------
Both utils.c and main.c compile just fine, but when I try to link it, I =
got:
$ gcc -o test main.o utils.o
utils.o(.bss+0x0):utils.c: multiple definition of `system_log_file'
main.o(.bss+0x0):main.c: first defined here
collect2: ld returned 1 exit status
But, if inside the header I put:
FILE *system_log_file;
instead of
FILE *system_log_file =3D NULL;
It works perfectly. Any ideas about why does this happens?
Thanks in advance.
|