template expansion problem-again
Anthony Shipman
als@tusc.com.au
Thu Apr 30 08:28:00 GMT 1998
I sent this before for egcs 1.0.1. I have retested it with
1.0.3-prerelease and the problem is still there. Can anyone tell me if
I am doing something wrong or if this is a compiler bug.
I compile using:
g++ -pipe -gstabs -O0 -g -fno-implicit-templates -o x.o -c x.cc
g++ -pipe -gstabs -O0 -g -o x2.o -c x2.cc
g++ -pipe -gstabs -O0 -g -o x x.o x2.o
and I get
x.cc:13: undefined reference to `__hashtable_iterator<pair<char const *const,
int>, char const *, hash<char const *>, select1st<pair<char const *const, int>
>, equal_to<char const *>, __default_alloc_template<false, 0>
>::operator++(void)'
collect2: ld returned 1 exit status
The sources are shown below. Using nm, I see that x2.o contains the
constructor for the __hashtable_iterator instance but not the
operator++(void).
If I build x from x.cc using
g++ -pipe -gstabs -O0 -g -o x.o -c x.cc
g++ -pipe -gstabs -O0 -g -o x x.o
then it all works fine. nm on x.o shows the operator++.
x.cc
----------------------------------
#include <hash_map.h>
typedef hash_map<const char*, int> MyMap;
int
main()
{
MyMap map;
map["abc"] = 3;
map["fred"] = 42;
for(MyMap::iterator iter = map.begin();
iter != map.end();
iter++)
{
cout << "mymap[" << iter->first << "] = " << iter->second << endl;
}
return 0;
}
x2.cc
-----------------------------------
#include <hash_map.h>
template class hash_map<const char*, int>;
--
Anthony Shipman "You've got to be taught before it's too late,
TUSC Computer Systems Pty Ltd Before you are six or seven or eight,
666 Doncaster Rd, Doncaster To hate all the people your relatives hate,
Melbourne, Australia, 3108 You've got to be carefully taught." R&H
More information about the Gcc
mailing list