From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32020 invoked by alias); 5 May 2006 21:29:23 -0000 Received: (qmail 31961 invoked by uid 22791); 5 May 2006 21:29:23 -0000 X-Spam-Check-By: sourceware.org Received: from nf-out-0910.google.com (HELO nf-out-0910.google.com) (64.233.182.184) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 05 May 2006 21:29:20 +0000 Received: by nf-out-0910.google.com with SMTP id k26so437755nfc for ; Fri, 05 May 2006 14:29:18 -0700 (PDT) Received: by 10.49.8.11 with SMTP id l11mr38322nfi; Fri, 05 May 2006 14:29:18 -0700 (PDT) Received: by 10.49.92.6 with HTTP; Fri, 5 May 2006 14:29:18 -0700 (PDT) Message-ID: <5b7094580605051429j3b4577c5o7d46dfb7f36fbc17@mail.gmail.com> Date: Fri, 05 May 2006 21:29:00 -0000 From: "Brian Budge" To: gcc-help Subject: gcc linking and address of template function MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2006-05/txt/msg00068.txt.bz2 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 int ll_uv_f(const gsl_vector *x, void *params, gsl_vector *f){ LL_uv_data *lld =3D static_cast< LL_uv_data* >(params= ); const real a =3D gsl_vector_get(x,0); const real b =3D gsl_vector_get(x,1); Vec v =3D lld->ll->eval(a, b) - lld->pt; for(int i =3D 0; i < 2; ++i){ gsl_vector_set(f, i, v[i]); } return GSL_SUCCESS; } template int ll_uv_df(const gsl_vector *x, void *params, gsl_matrix *J){...} template 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 dat(Vec(u,v), this); gsl_multiroot_function_fdf f =3D {ll_uv_f, ll_uv_df, ll_uv_fdf, 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(const gsl_vector *x, void *params, gsl_vector *f, gsl_matrix *J); template int ll_uv_fdf(const gsl_vector *x, void *params, gsl_vector *f, gsl_matrix *J); =2E =2E =2E template int ll_uv_df(const gsl_vector *x, void *params, gsl_matrix *J); template int ll_uv_df(const gsl_vector *x, void *params, gsl_matrix *J); =2E =2E =2E template int ll_uv_f(const gsl_vector *x, void *params, gsl_vector *f); template int ll_uv_f(const gsl_vector *x, void *params, gsl_vector *f); =2E =2E =2E 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