This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
linker anomaly
- To: egcs-bugs at cygnus dot com
- Subject: linker anomaly
- From: D Maley <d dot maley at airforce1 dot stmarys-belfast dot ac dot uk>
- Date: Mon, 26 Oct 1998 14:37:47 GMT
I am encountering linker problems with -frepo, namely "symbol `operator
new(unsigned int, void *)' is multiply defined:".
The problem does not occur with -falt-external-templates.
I am on a Pentium 200 with 128MB RAM running Solaris 2.6.
Today it has occured in a file test.cpp, (which as usual compiles OK with
-falt-external-templates).
test.cpp is much smaller than any previous example I had found, so I thought
I would submit it.
When I try to use -frepo, I get
*****************************************************************************
airforce1% mk
gcc -o x test.o -L/usr/dt/lib -lXm -L/usr/openwin/lib -lXt -lX11 -lsocket
-lg++ 2>>err
*** Error code 1
make: Fatal error: Command failed for target `x'
ld: fatal: symbol `operator new(unsigned int, void *)' is multiply defined:
(file /usr/local/lib/libg++.a(new.o) and file
/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/libgcc.a(new.o));
ld: fatal: File processing errors. No output written to x
collect2: ld returned 1 exit status
*****************************************************************************
If I remove -lg++ from my load flags, I get:
*****************************************************************************
gcc -DXTFUNCPROTO -DSUN -w -frepo -I/usr/openwin/include
-I/usr/dt/share/include -I. -c -o test.o test.cpp 2>>err
gcc -o x test.o -L/usr/dt/lib -lXm -L/usr/openwin/lib -lXt -lX11 -lsocket 2>>err
*** Error code 1
make: Fatal error: Command failed for target `x'
collect: recompiling test.cpp
collect: relinking
collect: recompiling test.cpp
collect: relinking
collect: recompiling test.cpp
collect: relinking
Undefined first referenced
symbol in file
w::MonitorTemplate<w::pair<int, int> >::containerBuild(int)test.o
ostream::operator<<(ostream &(*)(ostream &))test.o
w::MonitorTemplate<w::vector<w::pair<int, int> > > virtual tabletest.o
w::vectorMonitor<w::vector<w::pair<int, int> > > virtual tabletest.o
endl(ostream &) test.o
w::MonitorTemplate<w::pair<int, int> > type_info nodetest.o
cerr test.o
w::MonitorTemplate<w::pair<int, int> >::MonitorTemplate(w::MonitorBase *,
w::pair<int, int>)test.o
ostream::operator<<(char const *) test.o
w::MonitorTemplate<w::pair<int, int> > type_info functiontest.o
ld: fatal: Symbol referencing errors. No output written to x
collect2: ld returned 1 exit status
*****************************************************************************
When I try to create preprocessed output for submission, I get the stuff
below, so I have to send you the un-preprocessed version.
*****************************************************************************
airforce1% gcc -v --save-temps -DXTFUNCPROTO -DSUN -w -frepo
-I/usr/openwin/include -I/usr/dt/share/include -I. test.cpp
Reading specs from /usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/cpp -lang-c++ -v
-I/usr/openwin/include -I/usr/dt/share/include -I. -undef -D__GNUC__=2
-D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -Dunix -D__svr4__ -D__SVR4
-Dsun -D__unix__ -D__svr4__ -D__SVR4 -D__sun__ -D__unix -D__sun
-Asystem(svr4) -D__EXCEPTIONS -w -Asystem(unix) -Acpu(i386) -Amachine(i386)
-Di386 -D__i386 -D__i386__ -DXTFUNCPROTO -DSUN test.cpp test.ii
GNU CPP version egcs-2.91.57 19980901 (egcs-1.1 release) (i386 System V
Release 4)
#include "..." search starts here:
#include <...> search starts here:
/usr/openwin/include
/usr/dt/share/include
.
/usr/local/include/g++
/usr/local/lib/g++-include
/usr/local/include
/usr/local/i386-pc-solaris2.6/include
/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/include
/usr/include
End of search list.
/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/cc1plus test.ii
-quiet -dumpbase test.cc -w -version -frepo -o test.s
GNU C++ version egcs-2.91.57 19980901 (egcs-1.1 release)
(i386-pc-solaris2.6) compiled by GNU C version 2.7.2.1.
/usr/ccs/bin/as -V -Qy -o test.o test.s
as: WorkShop Compilers 4.2 alpha 14 Jun 1996
/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/collect2 -V -Y
P,/usr/ccs/lib:/usr/lib -Qy
/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/crt1.o
/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/crti.o
/usr/ccs/lib/values-Xa.o
/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/crtbegin.o
-L/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57
-L/usr/local/i386-pc-solaris2.6/lib -L/usr/ccs/bin -L/usr/ccs/lib
-L/usr/local/lib test.o -lgcc -lc -lgcc
/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/crtend.o
/usr/local/lib/gcc-lib/i386-pc-solaris2.6/egcs-2.91.57/crtn.o
collect: recompiling test.cpp
collect: relinking
ld: Software Generation Utilities - Solaris/ELF (3.0)
Undefined first referenced
symbol in file
w::MonitorTemplate<w::pair<int, int> >::determineValidity(void)test.o
__default_alloc_template<0, 0>::free_list test.o
w::IntMonitor<int>::IntMonitor(w::MonitorBase *, int)test.o
w::vector<w::pair<int, int> >::newMonitor(w::MonitorBase *) test.o
w::pairMonitor<int, int>::constructValue(w::MonitorBase *)test.o
w::setMonitor<w::set<x::Match> >::setMonitor(w::MonitorBase *,
w::set<x::Match>) test.o
w::MonitorTemplate<int> type_info functiontest.o
w::vector<w::pair<int, int> > virtual tabletest.o
w::MonitorTemplate<w::pair<int, int> > type_info nodetest.o
w::MonitorTemplate<int> type_info nodetest.o
w::MonitorTemplate<w::pair<int, int> >::constructCandidate(w::MonitorBase *)
test.o
w::set<x::Match> virtual table test.o
rb_tree<x::Match, x::Match, identity<x::Match>, less<x::Match>,
__default_alloc_template<0, 0> >::__erase(__rb_tree_node<x::Match> *)
test.o
w::MonitorTemplate<w::set<x::Match> >::determineValidity(void) test.o
w::vector<w::pair<int, int> > type_info functiontest.o
w::pairMonitor<int, int>::constructCandidate(void)test.o
rb_tree<x::Match, x::Match, identity<x::Match>, less<x::Match>,
__default_alloc_template<0, 0> >::insert_unique(__rb_tree_iterator<x::Match,
x::Match &, x::Match *>, x::Match const &) test.o
w::vector<w::pair<int, int> > type_info nodetest.o
vector<w::pair<int, int>, __default_alloc_template<0, 0>
>::insert_aux(w::pair<int, int> *, w::pair<int, int> const &)test.o
__default_alloc_template<0, 0>::refill(unsigned int)test.o
__malloc_alloc_template<0>::oom_malloc(unsigned int)test.o
w::pair<int, int> virtual table test.o
rb_tree<x::Match, x::Match, identity<x::Match>, less<x::Match>,
__default_alloc_template<0, 0> >::__copy(__rb_tree_node<x::Match> *,
__rb_tree_node<x::Match> *)test.o
w::MonitorTemplate<int> virtual tabletest.o
w::MonitorTemplate<w::pair<int, int> > type_info functiontest.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
****************************************************************************
************
/////////////////////////////////////////////////////////////
//
// test.cpp
//
/////////////////////////////////////////////////////////////
#include <stdio.h>
#include <cstdlib>
#include <pair.h>
#include <vector.h>
#include <set.h>
#define True 1;
#define False 0;
#define EXIT_ON_ERROR 0
#define errorLevel 2
#define RADIAL_LIMIT 36
void handleError(char *message, int theErrorLevel)
{
if (theErrorLevel>errorLevel)
printf("%s", message);
if (EXIT_ON_ERROR)
exit(0);
}
namespace w {
class MonitorBase {
public:
MonitorBase *descendant(int *, int);
virtual MonitorBase *child(int);
virtual bool determineValidity()=0;
virtual bool constructValue(MonitorBase *)=0;
bool constructValues(MonitorBase *);
inline bool validatorValidity() { return _validatorValid; }
virtual bool constructCandidate(MonitorBase *)=0;
virtual bool constructCandidate()=0;
MonitorBase *root();
int childNumber(MonitorBase *);
protected:
MonitorBase(MonitorBase *);
~MonitorBase();
bool _validatorValid;
MonitorBase *_parent, **_children;
int _childrenCount;
};
class CoMonitor {
public:
inline CoMonitor() { _valid = True; }
inline bool valid() { return _valid; }
inline bool validate() { return _valid = validity(); }
virtual MonitorBase *newMonitor(MonitorBase *)=0;
//protected:
virtual bool validity() { return True; }
bool _valid;
};
template <class S, class T> class pair : public std::pair<S, T>, public
CoMonitor {
public:
pair() : std::pair<S, T>() {}
pair(S s, T t) : std::pair<S, T>(s, t) {}
virtual bool validity();
MonitorBase *newMonitor(MonitorBase *);
virtual inline const char *const className() { return "pair<S, T>"; }
};
template <class T> class vector : public std::vector<T>, public CoMonitor {
public:
virtual bool validity();
MonitorBase *newMonitor(MonitorBase *);
inline const char *const className() { return "vector<T>"; }
};
template <class Key> class set : public std::set<Key>, public CoMonitor {
public:
virtual bool validity();
MonitorBase *newMonitor(MonitorBase *);
inline const char *const className() { return "set<T>"; }
};
template <class T> class MonitorTemplate : public MonitorBase {
public:
MonitorTemplate(MonitorBase *, T);
bool determineValidity();
inline T currentValue() { return _currentValue; }
inline T candidateValue() { return _candidateValue; }
inline T *value() { return &_currentValue; }
void containerBuild(int);
virtual void createChild(int)=0;
MonitorTemplate<T> *children(int);
virtual bool constructValue(MonitorBase *)=0;
protected:
bool constructCandidate(MonitorBase *);
T _candidateValue, _currentValue;
inline void copyToCandidate() { _candidateValue = _currentValue; }
inline void copyToCurrent() { _currentValue = _candidateValue; }
virtual bool constructCandidate()=0;
};
template <class T> class vectorMonitor : public MonitorTemplate<T> {
public:
vectorMonitor(MonitorBase *, T);
void createChild(int);
bool constructValue(MonitorBase *);
protected:
bool constructCandidate();
};
template <class T> class setMonitor : public MonitorTemplate<T> {
public:
setMonitor(MonitorBase *, T);
void createChild(int);
bool constructValue(MonitorBase *);
protected:
bool constructCandidate();
};
template <class S, class T> class pairMonitor : public
MonitorTemplate<pair<S, T> > {
public:
pairMonitor(MonitorBase *, pair<S, T>);
void createChild(int);
bool constructValue(MonitorBase *);
protected:
bool constructCandidate();
};
template <class T> class IntMonitor : public MonitorTemplate<T> {
public:
IntMonitor(MonitorBase *parent, T value);
bool validatorChange(T newValue, bool enquiry);
void createChild(int) {}
bool constructValue(MonitorBase *);
protected:
bool constructCandidate();
};
template <class T> MonitorBase *set<T>::newMonitor(MonitorBase *parent)
{
return new setMonitor<set<T> >(parent, *this);
}
template <class T> setMonitor<T>::setMonitor(MonitorBase *parent, T value) :
MonitorTemplate<T>(parent, value)
{
_children = new (MonitorBase *)[_childrenCount = value.size()];
typename T::iterator p=value.begin();
for (int i=0; i<value.size(); p++, i++)
_children[i] = (*p).newMonitor(this);
}
template <class T> void setMonitor<T>::createChild(int i) {}
template <class T> bool setMonitor<T>::constructCandidate() {}
template <class T> bool setMonitor<T>::constructValue(MonitorBase
*messageSender) {}
MonitorBase::MonitorBase(MonitorBase *parent)
{
_parent = parent;
_children = NULL;
_childrenCount = 0;
_validatorValid = True;
}
MonitorBase::~MonitorBase()
{
delete[ ] _children;
}
MonitorBase *MonitorBase::child(int buttonNumber)
{
if (_childrenCount>0)
return _children[buttonNumber];
else
return NULL;
}
int MonitorBase::childNumber(MonitorBase *messageSender)
{
for (int i=0; i<_childrenCount; i++)
if (_children[i]==messageSender)
return i;
handleError("messageSender not identified in MonitorBase::childNumber\n", 3);
return -1;
}
MonitorBase *MonitorBase::descendant(int *childNumbers, int size)
{
if (size==1) {
return child(childNumbers[0]);
} else
return child(childNumbers[0])->descendant(childNumbers+1, size-1);
}
bool MonitorBase::constructValues(MonitorBase *messageSender)
{
bool result = constructValue(messageSender);
if (_parent)
result = result && _parent->constructValues(this);
return result;
}
MonitorBase *MonitorBase::root()
{
if (_parent)
return _parent->root();
else
return this;
}
MonitorTemplate<int>::MonitorTemplate(MonitorBase *parent, int value) :
_currentValue(value), _candidateValue(value), MonitorBase(parent)
{ printf("creating validator of type int.\n");
}
template <class T> MonitorTemplate<T>::MonitorTemplate(MonitorBase *parent,
T value) : _currentValue(value), _candidateValue(value), MonitorBase(parent)
{ printf("creating validator of type %s.\n", value.className());
}
template <class T> bool MonitorTemplate<T>::determineValidity()
{
_validatorValid = True;
for (int i=0; i<_childrenCount; i++) {
if (!(_validatorValid = _children[i]->determineValidity()))
break;
}
return _validatorValid = _validatorValid && _currentValue.validate();
}
bool MonitorTemplate<int>::determineValidity()
{
return True;
}
template <class T> bool MonitorTemplate<T>::constructCandidate(MonitorBase
*messageSender)
{
T temp = _currentValue;
bool result = constructValue(messageSender);
copyToCandidate();
_currentValue = temp;
return result;
}
template <class T> void MonitorTemplate<T>::containerBuild(int n)
{
_children = new (MonitorBase *)[_childrenCount = n];
for (int i=0; i<_childrenCount; i++)
createChild(i);
}
template <class T> MonitorTemplate<T> *MonitorTemplate<T>::children(int i)
{
if (i<0 || i>_childrenCount-1) {
handleError("Illegitimate child requested\n", 3);
return NULL;
} else
return static_cast<MonitorTemplate<T> *>(_children[i]);
}
template <class T> MonitorBase *vector<T>::newMonitor(MonitorBase *parent)
{
return new vectorMonitor<vector<T> >(parent, *this);
}
template <class S, class T> MonitorBase *pair<S, T>::newMonitor(MonitorBase
*parent)
{
return new pairMonitor<S, T>(parent, *this);
}
template <class T> vectorMonitor<T>::vectorMonitor(MonitorBase *parent, T
value) : MonitorTemplate<T>(parent, value)
{
containerBuild(value.size());
}
template <class T> bool vectorMonitor<T>::constructCandidate()
{
int listLength = _candidateValue.size();
_candidateValue.clear();
for (int i=0; i<listLength; i++)
_candidateValue.push_back(static_cast<MonitorTemplate<typename
T::value_type> *>(_children[i])->candidateValue());
return _candidateValue.validity();
}
template <class T> void vectorMonitor<T>::createChild(int i)
{
_children[i] = _currentValue[i].newMonitor(this);
}
template <class T> bool vectorMonitor<T>::constructValue(MonitorBase
*messageSender)
{
bool result = True;
int listLength = _currentValue.size(), rowNumber=0, i=0;
for (; i<listLength; i++)
if (_children[i]==messageSender) {
rowNumber=i;
break;
}
if (i==listLength)
handleError("messageSender unidentified in
Monitor<T>::constructValue.\n", 3);
else {
_currentValue.erase(_currentValue.begin()+rowNumber-1);
_currentValue.insert(_currentValue.begin()+rowNumber-1,
static_cast<MonitorTemplate<typename T::value_type>
*>(messageSender)->currentValue());
}
return _currentValue.validate();
}
template <class T> IntMonitor<T>::IntMonitor(MonitorBase *parent, T value) :
MonitorTemplate<T>(parent, value)
{}
template <class T> bool IntMonitor<T>::validatorChange(T newValue, bool enquiry)
{
T previousValue = _currentValue;
_currentValue = newValue;
bool result = constructValues(this);
if (enquiry) {
_currentValue = previousValue;
constructValues(this);
}
return result;
}
bool IntMonitor<int>::constructValue(MonitorBase *)
{
return True;
}
bool IntMonitor<int>::constructCandidate()
{
copyToCandidate();
return True;
}
template <class T> bool IntMonitor<T>::constructValue(MonitorBase *)
{
return _currentValue.validate();
}
template <class T> bool IntMonitor<T>::constructCandidate()
{
copyToCandidate();
return _candidateValue.validate();
}
template <class S, class T> pairMonitor<S, T>::pairMonitor(MonitorBase
*parent, pair<S, T> value) : MonitorTemplate<pair<S, T> >(parent, value)
{
containerBuild(2);
}
void pairMonitor<int, int>::createChild(int i)
{
switch (i) {
case 0:
_children[i] = new IntMonitor<int>(this, _currentValue.first);
break;
case 1:
_children[i] = new IntMonitor<int>(this, _currentValue.second);
}
}
template <class S, class T> void pairMonitor<S, T>::createChild(int i)
{
switch (i) {
case 0:
_children[i] = _currentValue.first.newMonitor(this);
break;
case 1:
_children[i] = _currentValue.second.newMonitor(this);
}
}
template <class S, class T> bool pairMonitor<S,
T>::constructValue(MonitorBase *messageSender)
{
if (messageSender==_children[0]) {
_currentValue = pair<S, T>(static_cast<MonitorTemplate<S>
*>(_children[0])->currentValue(), _currentValue.second);
return _currentValue.validate();
} else if (messageSender==_children[1]) {
_currentValue = pair<S, T>(_currentValue.first,
static_cast<MonitorTemplate<T> *>(_children[1])->currentValue());
return _currentValue.validate();
} else
handleError("pairMonitor<T>::constructValue: message sender
unidentified.", 3);
}
template <class S, class T> bool pairMonitor<S, T>::constructCandidate()
{
_candidateValue = pair<S, T>(static_cast<MonitorTemplate<S>
*>(_children[0])->candidateValue(), static_cast<MonitorTemplate<T>
*>(_children[1])->candidateValue());
return candidateValue().validate();
}
} // end namespace w
namespace x {
using namespace w;
using w::vector;
using w::pair;
using w::set;
typedef pair<int, int> Set;
class Match : public vector<Set>
{
public:
unsigned int wins1();
bool validity();
};
unsigned int Match::wins1()
{
int wins=0;
for (iterator p=begin(); p<end(); p++)
wins += p->first>p->second;
}
typedef set<Match> MatchList;
bool Set::validity()
{
return abs(first-second)>1 && (first>5 || second>5);
}
bool Match::validity()
{
return wins1()==3 || wins1()==size()-3;
}
bool MatchList::validity()
{
return size()>0 && size()<6;
}
template <class S, class T> bool pair<S, T>::validity()
{
return True;
}
template <class T> bool vector<T>::validity()
{
return True;
}
template <class T> bool set<T>::validity()
{
return True;
}
void myProg()
{
Set s1(4, 6);
Set s2(1, 6);
Set s3(5, 7);
Match match1;
match1.push_back(s1);
match1.push_back(s2);
match1.push_back(s3);
MatchList matchList;
matchList.insert(matchList.begin(), match1);
Set s4(6, 0);
Set s5(6, 2);
Set s6(7, 9);
Set s7(7, 5);
Match match2;
match2.push_back(s4);
match2.push_back(s5);
match2.push_back(s6);
match2.push_back(s7);
matchList.insert(matchList.begin(), match2);
setMonitor<MatchList> v(NULL, matchList);
printf("%d\n", v.determineValidity());
}
} // end namespace x
void main(int argc, char *argv[])
{
x::myProg();
}
--- |================================================|
---- |-=| Dave Maley, M.A., M.Phil. |=-| ,---I
--- |================================================| |== U-----
--- | Computer Manager, St. Mary's College, Belfast | |== U (: |
--- |________________________________________________| | U----'-----
----- |________________________________/ ____====______| U' ()___(|
--- #__ //,-, ,-, ,-,\\ \| ///,-, ,-, \\ -------/,-,\_[
''( 0 )( 0 )( 0 )' o -''( 0 )( 0 ) \\#####====( 0 )
--------------'-'--'-'--'-'-------------------'-'--'-'--------------'-'----