This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

link error: multiple definition of


hi
  this is my code under redhat linux 8.0.

//a.h
#ifndef ah
#define ah
int i;
void add();
#endif 

//a.cpp
#include "a.h"
void add(){
  i++;
}

//c.cpp
#include "a.h"
int main(){
  i = 100;
  add();
  return 0;
}

g++ -c a.cpp     success
g++ c.cpp a.o 
error: a.o(.bss+0x0): multiple definition of 'i'
/tmp/cc0q7tmK.o(.bss+0x0): first defined here
collect2: ld returned 1 exit status.

can someone help me to solve problem? 
thanks.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]