Template Libraries

N

nifsmith

Hi

I am trying to create a library of stacks, lists templates in a DLL. I
am getting a linker error when trying to tie in my library to another
project.

Having posted earlier and read the faq on templates i had been including
a seperate template.cpp file when compiling my templates files in with a
project. However now that I have created a DLL file from my templates I
was getting a link error message.

I therefore revisited the faq and instead of declaring and defining my
templates in seperate files, i put both into the header files for the
seperate templates. This seemed a bit odd to me as now I am left with a
DLL which has a number of .cpp files which only have include header file
statements in them as all the code is now in the header files.

I compile my DLL (using MS instructions I am using VS 2003). To
simplify testing I am copying both the DLL and header files into an
"includes" folder within my project. I build the project and hey presto
no linker errors.

However I have a nagging doubt that I am leading myself up the garden
path and have a question.

I am copying the DLL and its header files into the includes folder. Is
this correct, if so is the inclusion of the DLL not a moot point. As the
header files are filled with both the definitions and declarations isn't
the DLL redundant. Include the header file and won't all the code from
the header file be included at that point. I am a bit of a newbie in C++
so this is a bit of an assumption by me.

To make sure that I am creating the library in the right way could
anyone point me to a source of info on this topic.

TYIA

nifsmith
 
V

Victor Bazarov

nifsmith said:
[...]
To make sure that I am creating the library in the right way could anyone
point me to a source of info on this topic.

Since C++ Standard doesn't really define what "a library" is or how
to create one, I'd strongly recommend asking in a compiler-specific
newsgroup. However, generally, where possible, there are three ways
to create a library involving templates. First is a bunch of headers
(and no type-independent object code), that's the Standard Library
way and Boost and some other template libraries are made using that
approach. Then you have a true object code where only *some* of
instantiations of the templates reside (and thus you limit the set of
types with which the templates can be used), I don't know of any
commercial examples of this, but there are probably some, involving
'float/double/complex<float>/complex<double>' types. And the third
one is based on the "export" keyword, which hasn't been implemented
in any of the widely used compilers AFAIK.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,282
Latest member
RoseannaBa

Latest Threads

Top