Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

templates and linking

templates and linking

templates and linking

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 "C" wrappers, explicit cdecl declarations, nothing seems to do the trick.
Any ideas or experiences?

RE: templates and linking

wich functions are not resolved?

John Fill


RE: templates and linking

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.

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...

RE: templates and linking

I think after including STL files you should write:
using namespace std;

John Fill


RE: templates and linking

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;
FILE TWO - gbvectf.cpp

#include "gbvect.h"
#include <stdlib.h>

template<class T>
{   data=NULL;   }
>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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close