Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

templates and linking

Status
Not open for further replies.

gregbackus

Programmer
May 15, 2001
4
US
I'm new to this site and I love it already!
Anyway - down to business -
I'm using 4.52, coding a vector class using templates
(template<class T> class vector)
I've got a header that contains only the declarations of the class and its functions
and a seperate file with the function definitions
(template<class T>
return_value vector<T>::func_name(args,...) --- like that )
I compile the function def file and put it into a library, but invariably I get unresolved
symbol errors. Always the same two functions. If I have the functions defined in the
same file as the class declaration, everything works fine (but TEXT segment is
too big. WAY too big).
so - are there tricks when using libraries that contain templatized classes/functions?
I've tried extern &quot;C&quot; wrappers, explicit cdecl declarations, nothing seems to do the trick.
Any ideas or experiences?
Thanks
 
wich functions are not resolved? John Fill
1c.bmp


ivfmd@mail.md
 
well, the undefined symbols are whatever functions are called in main().
The class has a constructor and a destructor, an insert() and remove() and a resize(), among others.
What ever function that is a memeber of vector<T> that is called from main() causes the link to fail.

I have used all the functions declared (along with the class) in a file: gbvect.h
I have all the function bodies defined in: gbvectf.cpp
compiled gbvectf.cpp into gbvectf.obj
added gbvectf.obj to a library called gbvect.lib
using tlib to examine this library shows that it has no public symbols.
the gbvectf.obj file compiles without a hitch - every file by-itself compiles just fine.

I didn't want to bog this message down with a large code puke - well I wanted to, but decided against it - but I could post the code if you want to look at it, but it'll be long...template function definitions...

Thanks for the interest.
GDB

PS - In the meantime I have put all of the function bodies in gbvect.h (not inline)
and that works OK, but I really want to get my head around TLINK...
 
I think after including STL files you should write:
using namespace std; John Fill
1c.bmp


ivfmd@mail.md
 
Nope. I'm not using STL - I'm trying to code a vector class from scratch. Borland 4.52
is pre-ANSI-standard, pre namespace even. Perhaps I am just a glutton for punishment, using this old version, but I'm a creature of habit.

I'll try to show this in a simplified form...
------------------------------------------------
FILE ONE - gbvect.h

template<class T>
class vector {
T* data;
public:
vector<T>();
};
-----------------------------------------------
FILE TWO - gbvectf.cpp

#include &quot;gbvect.h&quot;
#include <stdlib.h>

template<class T>
vector<T>::vector<T>()
{ data=NULL; }
-----------------------------------------------
FROM DOS PROMPT
>bcc -c gbvectf.cpp // compiles OK
>tlib gbvect.lib +gbvectf.obj // inserts module into library
-------------------------------------------------
OK. so now there is a .lib file that I examine from DOS
>tlib gbvect.lib, dump.lst
>type dump.lst

Publics by module

gbvectf size = 0
--------------------------------------------------
so the module is inserted, but there's no publics, nothing there to link tp.
Is there some trick involved when linking with template classes/functions?
I am at a loss.
Thanks.
GDB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top