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

* Re: gcc linking and address of template function
  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-11 10:41 ` Brian Gough
  1 sibling, 1 reply; 6+ messages in thread
From: Perry Smith @ 2006-05-07 11:56 UTC (permalink / raw)
  To: Brian Budge; +Cc: gcc-help

I may be right in front of my face but I don't see it.  Can you send  
a couple lines of what the link's error messages are like?

On May 5, 2006, at 4:29 PM, Brian Budge wrote:

> 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

* Re: gcc linking and address of template function
  2006-05-07 11:56 ` Perry Smith
@ 2006-05-07 22:53   ` Brian Budge
  2006-05-08 14:00     ` Perry Smith
  0 siblings, 1 reply; 6+ messages in thread
From: Brian Budge @ 2006-05-07 22:53 UTC (permalink / raw)
  To: Perry Smith; +Cc: gcc-help

Hi Perry -

Here are the errors I'm getting:

test/tester.o: In function
`STLocate2<OpenMesh::PolyMesh_ArrayKernelT<OpenMesh::DefaultTraits>,
double, CCStencil, BSphere<double, 2, OpenMesh::FaceHandle>
>::operator()(BSphere<double, 2, OpenMesh::FaceHandle> const&, bool)':
tester.cc:(.gnu.linkonce.t._ZN9STLocate2IN8OpenMesh21PolyMesh_ArrayKernelTINS0_13DefaultTraitsEEEd22CCStencil7BSphereIdLi2ENS0_10FaceHandleEEEclERKS7_b+0x30e):
undefined reference to `ll_uv_f(gsl_vector const*, void*,
gsl_vector*)'
tester.cc:(.gnu.linkonce.t._ZN9STLocate2IN8OpenMesh21PolyMesh_ArrayKernelTINS0_13DefaultTraitsEEEd22CCStencil7BSphereIdLi2ENS0_10FaceHandleEEEclERKS7_b+0x318):
undefined reference to `ll_uv_df(gsl_vector const*, void*,
gsl_matrix*)'
tester.cc:(.gnu.linkonce.t._ZN9STLocate2IN8OpenMesh21PolyMesh_ArrayKernelTINS0_13DefaultTraitsEEEd22CCStencil7BSphereIdLi2ENS0_10FaceHandleEEEclERKS7_b+0x322):
undefined reference to `ll_uv_fdf(gsl_vector const*, void*,
gsl_vector*, gsl_matrix*)'

Note I've only instantiated my classes with the template type =
CCStencil, so there aren't any errors regarding BSStencil.

When I do an nm on one of my .o files (which is on the link line), I get this:
00000000 W _Z7ll_uv_fI21BSStencilEiPK10gsl_vectorPvPS1_
00000000 W _Z7ll_uv_fI22CCStencilEiPK10gsl_vectorPvPS1_
00000000 W _Z8ll_uv_dfI21BSStencilEiPK10gsl_vectorPvP10gsl_matrix
00000000 W _Z8ll_uv_dfI22CCStencilEiPK10gsl_vectorPvP10gsl_matrix
00000000 W _Z9ll_uv_fdfI21BSStencilEiPK10gsl_vectorPvPS1_P10gsl_matrix
00000000 W _Z9ll_uv_fdfI22CCStencilEiPK10gsl_vectorPvPS1_P10gsl_matrix

nm --demangle gives:

00000000 W int ll_uv_f<BSStencil>(gsl_vector const*, void*, gsl_vector*)
00000000 W int ll_uv_f<CCStencil>(gsl_vector const*, void*, gsl_vector*)
00000000 W int ll_uv_df<BSStencil>(gsl_vector const*, void*, gsl_matrix*)
00000000 W int ll_uv_df<CCStencil>(gsl_vector const*, void*, gsl_matrix*)
00000000 W int ll_uv_fdf<BSStencil>(gsl_vector const*, void*,
gsl_vector*, gsl_matrix*)
00000000 W int ll_uv_fdf<CCStencil>(gsl_vector const*, void*,
gsl_vector*, gsl_matrix*)


Thanks!
  Brian


On 5/7/06, Perry Smith <pedz@easesoftware.com> wrote:
> I may be right in front of my face but I don't see it.  Can you send
> a couple lines of what the link's error messages are like?
>
> On May 5, 2006, at 4:29 PM, Brian Budge wrote:
>
> > 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

* Re: gcc linking and address of template function
  2006-05-07 22:53   ` Brian Budge
@ 2006-05-08 14:00     ` Perry Smith
  0 siblings, 0 replies; 6+ messages in thread
From: Perry Smith @ 2006-05-08 14:00 UTC (permalink / raw)
  To: Brian Budge; +Cc: gcc-help

I'm hoping someone else might chime in and help you out as well.  I'm  
just guessing here.

But it looks to me as if you are referencing non-template functions  
with names like ll_uv_fdf  somewhere in your code.  Is that possible?

I would assume that a reference to a template function would have the  
template parameter in the names since the definitions have the  
template parameter in their names.

I would do the nm --demangle of your .o's again and grep for one  
specific name like "ll_uv_fdf" and see what pops out.  I'm hoping you  
can see the pattern of what a reference looks like and what a  
definition looks like.  Also, maybe not include one of the .o files  
that has the instanciations and see what errors pop out to try and  
figure out if an undefined reference to a function from a template  
has the template parameter in the name or not.

HTH,
Perry

On May 7, 2006, at 5:52 PM, Brian Budge wrote:

> Hi Perry -
>
> Here are the errors I'm getting:
>
> test/tester.o: In function
> `STLocate2<OpenMesh::PolyMesh_ArrayKernelT<OpenMesh::DefaultTraits>,
> double, CCStencil, BSphere<double, 2, OpenMesh::FaceHandle>
>> ::operator()(BSphere<double, 2, OpenMesh::FaceHandle> const&, bool)':
> tester.cc: 
> (.gnu.linkonce.t._ZN9STLocate2IN8OpenMesh21PolyMesh_ArrayKernelTINS0_1 
> 3DefaultTraitsEEEd22CCStencil7BSphereIdLi2ENS0_10FaceHandleEEEclERKS7_ 
> b+0x30e):
> undefined reference to `ll_uv_f(gsl_vector const*, void*,
> gsl_vector*)'
> tester.cc: 
> (.gnu.linkonce.t._ZN9STLocate2IN8OpenMesh21PolyMesh_ArrayKernelTINS0_1 
> 3DefaultTraitsEEEd22CCStencil7BSphereIdLi2ENS0_10FaceHandleEEEclERKS7_ 
> b+0x318):
> undefined reference to `ll_uv_df(gsl_vector const*, void*,
> gsl_matrix*)'
> tester.cc: 
> (.gnu.linkonce.t._ZN9STLocate2IN8OpenMesh21PolyMesh_ArrayKernelTINS0_1 
> 3DefaultTraitsEEEd22CCStencil7BSphereIdLi2ENS0_10FaceHandleEEEclERKS7_ 
> b+0x322):
> undefined reference to `ll_uv_fdf(gsl_vector const*, void*,
> gsl_vector*, gsl_matrix*)'
>
> Note I've only instantiated my classes with the template type =
> CCStencil, so there aren't any errors regarding BSStencil.
>
> When I do an nm on one of my .o files (which is on the link line),  
> I get this:
> 00000000 W _Z7ll_uv_fI21BSStencilEiPK10gsl_vectorPvPS1_
> 00000000 W _Z7ll_uv_fI22CCStencilEiPK10gsl_vectorPvPS1_
> 00000000 W _Z8ll_uv_dfI21BSStencilEiPK10gsl_vectorPvP10gsl_matrix
> 00000000 W _Z8ll_uv_dfI22CCStencilEiPK10gsl_vectorPvP10gsl_matrix
> 00000000 W _Z9ll_uv_fdfI21BSStencilEiPK10gsl_vectorPvPS1_P10gsl_matrix
> 00000000 W _Z9ll_uv_fdfI22CCStencilEiPK10gsl_vectorPvPS1_P10gsl_matrix
>
> nm --demangle gives:
>
> 00000000 W int ll_uv_f<BSStencil>(gsl_vector const*, void*,  
> gsl_vector*)
> 00000000 W int ll_uv_f<CCStencil>(gsl_vector const*, void*,  
> gsl_vector*)
> 00000000 W int ll_uv_df<BSStencil>(gsl_vector const*, void*,  
> gsl_matrix*)
> 00000000 W int ll_uv_df<CCStencil>(gsl_vector const*, void*,  
> gsl_matrix*)
> 00000000 W int ll_uv_fdf<BSStencil>(gsl_vector const*, void*,
> gsl_vector*, gsl_matrix*)
> 00000000 W int ll_uv_fdf<CCStencil>(gsl_vector const*, void*,
> gsl_vector*, gsl_matrix*)
>
>
> Thanks!
>  Brian
>
>
> On 5/7/06, Perry Smith <pedz@easesoftware.com> wrote:
>> I may be right in front of my face but I don't see it.  Can you send
>> a couple lines of what the link's error messages are like?
>>
>> On May 5, 2006, at 4:29 PM, Brian Budge wrote:
>>
>> > 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

* Re: gcc linking and address of template function
  2006-05-05 21:29 gcc linking and address of template function Brian Budge
  2006-05-07 11:56 ` Perry Smith
@ 2006-05-11 10:41 ` Brian Gough
  2006-05-11 13:39   ` Brian Budge
  1 sibling, 1 reply; 6+ messages in thread
From: Brian Gough @ 2006-05-11 10:41 UTC (permalink / raw)
  To: Brian Budge; +Cc: gcc-help

Brian Budge writes:
 > 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 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.

Did you find the cause of this problem?

-- 
Brian Gough
(GSL Maintainer)

Network Theory Ltd,
Commercial support for GSL --- http://www.network-theory.com/

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

* Re: gcc linking and address of template function
  2006-05-11 10:41 ` Brian Gough
@ 2006-05-11 13:39   ` Brian Budge
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Budge @ 2006-05-11 13:39 UTC (permalink / raw)
  To: Brian Gough; +Cc: gcc-help

No, amazingly enough.  I actually gave up on this and wrote my own
templates based solver.

If I get some time one of these days, I may try to reconstruct this.

Thanks,
  Brian

On 5/11/06, Brian Gough <bjg@network-theory.co.uk> wrote:
> Brian Budge writes:
>  > 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 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.
>
> Did you find the cause of this problem?
>
> --
> Brian Gough
> (GSL Maintainer)
>
> Network Theory Ltd,
> Commercial support for GSL --- http://www.network-theory.com/
>

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