This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
template expansion problem
- To: egcs at cygnus dot com (EGCS discussion list)
- Subject: template expansion problem
- From: Anthony Shipman <als at tusc dot com dot au>
- Date: Mon, 27 Apr 1998 03:28:19 +1000 (EST)
This is with egcs 1.0.1 on Linux, Redhat 4.2.
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