Topic: need help compiling (linking) Borland C++ programs using templates


Author: jamshid@ut-emx.uucp (Jamshid Afshar)
Date: 22 Dec 92 21:52:07 GMT
Raw View
In article <1992Dec17.231411.10943@engage.pko.dec.com> chou@riscee.pko.dec.com (Jesse Chou WSG/SECG) writes:
>This may be a very basic and silly question to ask but I am new to Borland
>c++.  It is greatly appreciated that someone could enlighten me or give me
>pointer to a FAQ.

The comp.lang.c++ FAQL is available by anonymous ftp at
sun.soe.clarkson.edu in the file pub/C++/FAQ (though there's not much
on templates).

>I am writing a list class using template and got link error:
>Error: Undefined symbol slist_base::append(slink near*) in module tpc.cpp
>I had a similar error using other c++ compiler and found that I have to use
>a command line switch with the compiler.

Different compilers currently do not handle the generation of template
functions in the same way.  The ARM leaves a lot unspecified and I'm
not sure what ANSI C++ will say about it.  Make sure you read your
compiler manuals as there are often different ways to do it even with
the same compiler, each method offering different tradeoffs.

The easiest way to do deal with this under BC++ (and I believe gcc) is
to just #include the .cpp file containing the non-inline template
functions in the corresponding header file.

 // List.h
 #ifndef List_H
 #define List_H

 template<class T> class List { /*...*/ };
 //...

 #ifndef DONT_NEED_CPP
 #include "List.cpp"
 #endif

 #endif // List_H

Jamshid Afshar
jamshid@emx.utexas.edu







Author: chou@riscee.pko.dec.com (Jesse Chou WSG/SECG)
Date: 17 Dec 92 23:14:11 GMT
Raw View
This may be a very basic and silly question to ask but I am new to Borland
c++.  It is greatly appreciated that someone could enlighten me or give me
pointer to a FAQ.


I am writing a list class using template and got link error:

Error: Undefined symbol slist_base::append(slink near*) in module tpc.cpp


I had a similar error using other c++ compiler and found that I have to use
a command line switch with the compiler.  I suppose that someone could
easily point to me what I should do in my makefile.  Or maybe there is
other problems that I am not aware of.  In any rate, thanks in advance.



Jesse



--
Jesse Chou -- chou@riscee.enet.dec.com

These words are entered into net by the keyboard.
I am not responsible for them; neither is my employer.


--
Jesse Chou -- chou@riscee.enet.dec.com

These words are entered into net by the keyboard.
I am not responsible for them; neither is my employer.