public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* SV: Explicit instantiation of function templates in libraries
@ 2004-04-14 16:18 Sigurd Saue
  0 siblings, 0 replies; only message in thread
From: Sigurd Saue @ 2004-04-14 16:18 UTC (permalink / raw)
  To: gcc-help

In case someone was starting to apply any brain power on this one, I solved
the problem myself. And it's a bit embarrassing: It had nothing to do with
templates at all, but rather the linking order of libraries.

Sigurd

-----Opprinnelig melding-----
Fra: Sigurd Saue [mailto:sigu-sa@online.no] 
Sendt: 14. april 2004 15:16
Til: 'gcc-help@gcc.gnu.org'
Emne: Explicit instantiation of function templates in libraries

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?

Thanks for any help.
Sigurd Saue

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-04-14 16:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-14 16:18 SV: Explicit instantiation of function templates in libraries Sigurd Saue

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