C++ Compiler bug ??
C++ Compiler bug ??
- Subject: C++ Compiler bug ??
- From: kubernan <email@hidden>
- Date: Mon, 14 Jan 2002 20:23:54 +0100
Hello,
Big problem with my ObjC++ code : i have one .h file which contains a
template C++ class definition.
When this file is imported (or included) in my two .mm (ObjC++) files
the build phase returns :
---- a part of the errors ---
/usr/bin/ld: multiple definitions of symbol ___vt_7BP_Foo
/Users/kubernan/Projects/Think_Factory/GUI/Neural Network Kitchen/Neural
Network Kitchen 3.0/build/intermediates/Neural Network Kitchen
3.0.build/Objects/ppc/File1.o definition of ___vt_7BP_Foo in section
(__DATA,__const)
/Users/kubernan/Projects/Think_Factory/GUI/Neural Network Kitchen/Neural
Network Kitchen 3.0/build/intermediates/Neural Network Kitchen
3.0.build/Objects/ppc/File2.o definition of ___vt_7BP_Foo in section
(__DATA,__const)
On the Web i found some threads about this kind of error. Some of
threads (C++ discussion) explain this pb appears with an earlier release
of gcc (?!).
Doing "man ld" i found this :
Apple Computer, Inc. July 28, 2001
LD(1)
-multiply_defined treatment
Specifies how multiply defined symbols in dynamic
libraries when -twolevel_namespace is in effect are
to be treated. treatment can be: error, warning,
or suppress. Which cause the treatment of multiply
defined symbols in dynamic libraries as either,
errors, warnings, or suppresses the checking of
multiply symbols from dynamic libraries when
-twolevel_namespace is in effect. The default is
to treat multiply defined symbols in dynamic
libraries as warnings when -twolevel_namespace is
in effect.
I tried -multiply_defined and -twolevel_namespace but it has no effect.
Still have linker pb.
So, do you think it's a compiler bug ?
Here a sample pseudo code :
------------ myClass.h --------------------
#ifndef _MYCLASS_H_
#define _MYCLASS_H_
#include<stdio.h>
#include<fstream.h>
#include<iostream.h>
#include<stdlib.h>
#include<ctype.h>
#include<assert.h>
#include"backprop.h"
#include"common.h"
#include<time.h>
#include<stdlib.h>
template<class xxxx>
class Foo : public aClass_def
{
// code
}
@endif
----------- File1.mm : -----------------
#import "File1.h"
#include"myClass.h" // C++ with template class
@implementation File1
- (id)init {
some Code
}
return self;
}
-(void)aMethod
{
// call of the myClass (in C++)
}
----------- File2.mm : -----------------
#import "File2.h"
#include"myClass.h" // C++ (the same as File1.h)
@implementation File2
- (id)init {
some Code
}
return self;
}
-(void)aMethod
{
// call of the myClass (in C++)
}