hallo,
I'm pretty new to C and I'm having some problems while compiling multiple files; here what I do:
I've got 3 files:
1.cpp , 2.cpp , INIT.h
and these are the files:
1.cpp:
#include <INIT.h>
int main (int argc, char *argv[]) {
a=3;
printf("%d",a);
}
2.cpp:
#include <INIT.h>
void funzione(){
a=2;
}
INIT.h:
#ifndef HEADER
#define HEADER
#include <stdio.h>
int a;
#endif
Ok, now I compile them in this way:
g++ -c 1.cpp -I.
g++ -c 2.cpp -I.
but when I type:
g++ 1.o 2.o
it says:
2.o: (.bss+0x0): multiple definition of `a'
1.o: (.bss+0x0): first defined here
collect2: ld returned 1 exit status
why is it so?
thanks a lot for your help
Ale