"Rafi Kfir" <ra*******@telrad.co.il> wrote in message
news:f7**************************@posting.google.c om...
"Hi,
This is a very simple question that confuses me (probably due to some
lack of knowledge...)
I will illustrate my problem with a smiple example:
My project has the following files:
file1.c
#include file3.h
file2.c
#include file3.h
file3.h
#ifndef _file3
#define _file3
char a[4]; //this one causes no error
It should do
char b[]="Hello"; //this one causes the error
#endif
Can anybody explain why I'm getting the link error upon compilation.
Do it like this
// file3.h
extern char a[];
extern char b[];
// either file1.c or file2.c not both
char a[4]; //this one causes no error
char b[]="Hello"; //this one causes the error
You need to understand the difference between a declaration and a
definition. You can only have one definition. What you had before put the
definition in the header file. When you include that header file in more
that one .c file you get multiple definitions and linker errors.
The way I did it, you have a declaration in the header file, you can have as
many declarations as you like. But I put the definitions in one of the .c
files.
john