multiple definition of `main'
???
xuesongguo@sohu-inc.com
Mon Jan 21 17:56:00 GMT 2002
Including of header file equal to insert the the whole of the header file
into the line where '#include' appeared.
if you have header file myheader.h, mycfile1.c,mycfile2.c:
/*************************myheader.h***********************************/
void myfunction(){printf("a function in a header file without inline");}
/*************************end of
myheader.h***********************************/
/*************************mycfile1.c***********************************/
#include "myhdaer.h"
void main(){}
/*************************end of
mycfile1.c***********************************/
/*************************mycfile1.c***********************************/
#include "myhdaer.h"
void something(){}
/*************************end of
mycfile1.c***********************************/
then mycfile1.c equal to :
void myfunction(){printf("a function in a header file without inline");}
void main(){}
and mycfile2.c equal to:
void myfunction(){printf("a function in a header file without inline");}
void something(){}
when you link the two file together, you will get a multiple definitions
error,
but if myfunction is inlined ,it's ok.
---------------------------------------------------------
1uNCEE
Guo Xuesong
Sohu-inc
phone: +86 13910010559
email: xuesongguo@sohu-inc.com
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org]On
Behalf Of Devrim Erdem
Sent: Tuesday, January 22, 2002 12:45 AM
To: gcc-help
Subject: multiple definition of `main'
Hello,
I am having a problem of multiple definitions which I couldn't figure out.
The full linker is here :
Obj_Linux_IA32/Graphics.a(DynModel.o): In function `Gfx::TestModel
type_info function':
/vires/devrim/Projects/Fstd/Src/Modules/Graphics/DynModel.hh(.text+0x0):
multiple definition of `main'
.Obj_Linux_IA32/Graphics.a(Graphics.o)(.text+0x0):/vires/devrim/Projects/Fst
d/Src/Modules/Graphics/Graphics.cc:
first defined here
collect2: ld returned 1 exit status
This happens when I use the class TestModel ( which is in DynModel.hh ). It
is true that Graphics.cc has a main but it is definetely not multiply
defined.
I had experienced similar problems when I implement a class method in header
file out of the class scope without using the "inline" word. Adding inline
would fix those. This one makes me clueless.
Any ideas...?
gcc-2.95.3-124 on SuSE 7.3
Regards.
--
Devrim Erdem
-------------------------------------
VIRES Simulationstechnologie GmbH
Oberaustrasse 34
83026 Rosenheim
Germany
phone +49.8031.463640
fax +49.8031.463645
email devrim@vires.com
internet www.vires.com
-------------------------------------
More information about the Gcc-help
mailing list