By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Template Libraries

P: n/a


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

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.



Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
"nifsmith" <ha*********> wrote...
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.

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.