public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc linking and address of template function
@ 2006-05-05 21:29 Brian Budge
  2006-05-07 11:56 ` Perry Smith
  2006-05-11 10:41 ` Brian Gough
  0 siblings, 2 replies; 6+ messages in thread
From: Brian Budge @ 2006-05-05 21:29 UTC (permalink / raw)
  To: gcc-help

Hi all -

I'm attempting to use gsl (gnu scientific library) from my C++
program.  gsl is a C program, and I need to pass function pointers to
gsl to make it do it's magic on my data.

The problem I'm having stems from the fact that I need my functions to
be template functions.

I can get everything to compile, but I can't get it to link.

The gist is like this:

template<class Stencil>
int ll_uv_f(const gsl_vector *x, void *params, gsl_vector *f){
    LL_uv_data<Stencil> *lld = static_cast< LL_uv_data<Stencil>* >(params);
    const real a = gsl_vector_get(x,0);
    const real b = gsl_vector_get(x,1);
    Vec v = lld->ll->eval(a, b) - lld->pt;
    for(int i = 0; i < 2; ++i){
        gsl_vector_set(f, i, v[i]);
    }
    return GSL_SUCCESS;
}

template<class Stencil>
int ll_uv_df(const gsl_vector *x, void *params, gsl_matrix *J){...}

template<class Stencil>
int ll_uv_fdf(const gsl_vector *x, void *params, gsl_vector *f,
gsl_matrix *J){...}

The calling function then contains the code:

LL_uv_data<BaseStencil> dat(Vec(u,v), this);
gsl_multiroot_function_fdf f = {ll_uv_f<BaseStencil>,
                                           ll_uv_df<BaseStencil>,
                                           ll_uv_fdf<BaseStencil>,
                                           2, &dat};

I also explicitly instantiate the template functions for several
instances in a .cc file:

//explicit instantiation of template functions
template int ll_uv_fdf<CCStencil>(const gsl_vector *x, void *params,
gsl_vector *f, gsl_matrix *J);
template int ll_uv_fdf<BSStencil>(const gsl_vector *x, void *params,
gsl_vector *f, gsl_matrix *J);
.
.
.
template int ll_uv_df<CCStencil>(const gsl_vector *x, void *params,
gsl_matrix *J);
template int ll_uv_df<BSStencil>(const gsl_vector *x, void *params,
gsl_matrix *J);
.
.
.
template int ll_uv_f<CCStencil>(const gsl_vector *x, void *params,
gsl_vector *f);
template int ll_uv_f<BSStencil>(const gsl_vector *x, void *params,
gsl_vector *f);
.
.
.

The program compiles fine, and the functions int ll_uv_*() are found
by the nm utility to be in a .o file.

The program still won't link.  Anyone have any ideas?  Is this
something I'm doing wrong?  The gcc version is 3.4.5-r1, and this is
on a xeon box running linux.

Thanks,
  Brian

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-05-11 13:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-05 21:29 gcc linking and address of template function Brian Budge
2006-05-07 11:56 ` Perry Smith
2006-05-07 22:53   ` Brian Budge
2006-05-08 14:00     ` Perry Smith
2006-05-11 10:41 ` Brian Gough
2006-05-11 13:39   ` Brian Budge

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