From: llewelly@xmission.com
To: "Sigurd Saue" <sigu-sa@online.no>
Cc: <gcc-help@gcc.gnu.org>
Subject: Re: Explicit instantiation of function templates in libraries
Date: Thu, 15 Apr 2004 14:01:00 -0000 [thread overview]
Message-ID: <s3r7jwh732c.fsf@xmission.xmission.com> (raw)
In-Reply-To: <004901c42222$9540f070$0a01a8c0@SIGURD>
"Sigurd Saue" <sigu-sa@online.no> writes:
> Could someone please explain how to do explicit instantiation of function
> templates in a static library? I get "undefined reference" linking errors
> when doing it like this:
>
> ////////////////////////////////////////
> //vvEigenSystem.h - template declaration
>
> template <class T> bool jacobi(vnl_matrix<T>& input, vnl_matrix<T>& vectors,
> vnl_vector<T>& values);
>
>
> /////////////////////////////////////////
> //vvEigenSystem.cpp - template definition and explicit instantiation
>
> #include "vvEigenSystem.h"
>
> // Definition
> template <class T> bool jacobi(vnl_matrix<T>& input, vnl_matrix<T>& vectors,
> vnl_vector<T>& values) { ... }
>
> // Explicit instantiation
> template bool jacobi(vnl_matrix<float>& input, vnl_matrix<float>& vectors,
> vnl_vector<float>& values);
>
> /////////////////////////////////////////
> //vvCalculations.cpp - using the template function
>
> #include "vvEigenSystem.h"
>
> void calculate()
> {
> ...
> jacobi(m_eigProblem, m_eigVectors, m_eigValues);
> ...
> }
>
> If vvCalculations.cpp is in the same translations unit (same static library)
> as vvEigenSystem.* then this works fine, no errors. If they're in two
> different static libraries the linker reports an "undefined reference" on
> the jacobi-function. I have not used any pragmas or compiler options so far,
> since the information give on this is very confusing ("deprecated",
> "shouldn't be used", "makes no difference", etc.). We use gcc 3.3.2. What's
> the right way to do this?
gcc does not yet support any form of seperate compiliation for
templates. So the full definition of every template must be
#included in every translation unit which instantiates it.
prev parent reply other threads:[~2004-04-15 14:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-14 13:16 Sigurd Saue
2004-04-15 14:01 ` llewelly [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=s3r7jwh732c.fsf@xmission.xmission.com \
--to=llewelly@xmission.com \
--cc=gcc-help@gcc.gnu.org \
--cc=sigu-sa@online.no \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).