🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #223

linking template classes

#223
From: Hans Juergen Thoennissen
Date: Tue, 08 Sep 1992 11:57
53 lines
1469 bytes
Hello,

this is my first posting in the usenet so please sorry for choosing the wrong groups ..... but I need help !!!

I have a problem with the GNU C++ V2.1 Compiler on my SPARCstation SLC, using  sunos4.1.1 !!!

The problem is the following:

FILE1:         foo_test.cc

#include "foo.h"

main() {
	Array<int> ALF;
}

FILE2:       foo.h

template <class Typ>
class Array {
public:   Array() {Init();}
private: void Init();
};

FILE3:     foo.cc

#include "foo.h"
template <class Typ> void
Array<Typ>::Init() {
}


COMMANDS:

g++ -c  foo.cc
g++ foo_test.cc foo.o

This results in the following linker error:

ld: Undifined symbol
      _Init__t5Array1Zi
collect:   /usr/bin/ld returned 2 exit status


But if I put all 3 files in one, it works. 

It seems, that the linker has a problem with the template class. 
Can anybody explain what I am doing wrong or if something is not
installed correctly.

Thanks in advance

Hans-Juergen
Technical Details
Message-ID: <1992Sep8.115747.137@Urmel.Informatik.RWTH-Aachen.DE>
Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!picasso.informatik.rwth-aachen.de!thoennis

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.help,comp.lang.c++
Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!picasso.informatik.rwth-aachen.de!thoennis
From: thoennis@picasso.informatik.rwth-aachen.de (Hans Juergen Thoennissen)
Subject: linking template classes
Message-ID: <1992Sep8.115747.137@Urmel.Informatik.RWTH-Aachen.DE>
Sender: gnulists@ai.mit.edu
Organization: University of Aachen, W-Germany
Date: Tue, 8 Sep 1992 11:57:47 GMT
Lines: 57