Page 1 of 1

lapacke.h: template with C linkage error [patch included]

PostPosted: Fri Jan 11, 2013 4:05 pm
by robzumwalt
This has been covered before here:

viewtopic.php?f=2&t=2284

But this issue is still present in lapack 3.4.2 with gcc 4.7.2 on Fedora 17.

It would be great if such a fix could make it in the next release (3.4.3?)

Here is the diff that was needed to fix the issue, only lapacke.h needs to be changed.
The issue is that there cannot be #include <complex.h> (which has templates) inside an extern "C" block.

Code: Select all
@@ -41,10 +41,6 @@
 #include "lapacke_config.h"
 #endif
 
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
 #include <stdlib.h>
 
 #ifndef lapack_int
@@ -106,6 +102,10 @@ lapack_complex_double lapack_make_complex_double( double re, double im );
 
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
 #ifndef LAPACKE_malloc
 #define LAPACKE_malloc( size ) malloc( size )
 #endif

Re: lapacke.h: template with C linkage error [patch included

PostPosted: Sun Jan 27, 2013 1:49 pm
by admin
Thank you rob.

this is the current lapacke.h for the next release. You can access it on our svn.
I believe this address the problem.
Julie
Code: Select all
#ifndef _LAPACKE_CONFIG_H_
#define _LAPACKE_CONFIG_H_

#ifdef __cplusplus
#if defined(LAPACK_COMPLEX_CPP)
#include <complex>
#endif
extern "C" {
#endif /* __cplusplus */

#include <stdlib.h>

#ifndef lapack_int
#if defined(LAPACK_ILP64)
#define lapack_int              long
#else
#define lapack_int              int
#endif
#endif

#ifndef lapack_logical
#define lapack_logical          lapack_int
#endif

#ifndef LAPACK_COMPLEX_CUSTOM

#if defined(LAPACK_COMPLEX_STRUCTURE)

typedef struct { float real, imag; } _lapack_complex_float;
typedef struct { double real, imag; } _lapack_complex_double;
#define lapack_complex_float  _lapack_complex_float
#define lapack_complex_double _lapack_complex_double
#define lapack_complex_float_real(z)  ((z).real)
#define lapack_complex_float_imag(z)  ((z).imag)
#define lapack_complex_double_real(z)  ((z).real)
#define lapack_complex_double_imag(z)  ((z).imag)

#elif defined(LAPACK_COMPLEX_C99)

#include <complex.h>
#define lapack_complex_float    float _Complex
#define lapack_complex_double   double _Complex
#define lapack_complex_float_real(z)       (creal(z))
#define lapack_complex_float_imag(z)       (cimag(z))
#define lapack_complex_double_real(z)       (creal(z))
#define lapack_complex_double_imag(z)       (cimag(z))

#elif defined(LAPACK_COMPLEX_CPP)

#define lapack_complex_float std::complex<float>
#define lapack_complex_double std::complex<double>
#define lapack_complex_float_real(z)       ((z).real())
#define lapack_complex_float_imag(z)       ((z).imag())
#define lapack_complex_double_real(z)       ((z).real())
#define lapack_complex_double_imag(z)       ((z).imag())

#else

#include <complex.h>
#define lapack_complex_float    float _Complex
#define lapack_complex_double   double _Complex
#define lapack_complex_float_real(z)       (creal(z))
#define lapack_complex_float_imag(z)       (cimag(z))
#define lapack_complex_double_real(z)       (creal(z))
#define lapack_complex_double_imag(z)       (cimag(z))

#endif

lapack_complex_float lapack_make_complex_float( float re, float im );
lapack_complex_double lapack_make_complex_double( double re, double im );

#endif

#ifndef LAPACK_malloc
#define LAPACK_malloc( size )   malloc( size )
#endif

#ifndef LAPACK_free
#define LAPACK_free( p )        free( p )
#endif

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _LAPACKE_CONFIG_H_ */

Re: lapacke.h: template with C linkage error [patch included

PostPosted: Mon Jan 28, 2013 4:31 pm
by robzumwalt
Hi Julie,

Thank you for your time. I do not see it in the lapack svn as of r1379. Is there another svn that I should use other than the one mentioned on this page? http://www.netlib.org/lapack/#_svn_access

Re: lapacke.h: template with C linkage error [patch included

PostPosted: Fri Mar 01, 2013 2:49 pm
by arwild01
I think I'm running into the same issue and I'm a bit confused as to the status of the fix. Rob specifically mentions the issue as lapacke.h, but the file you posted is lapacke_config.h which doesn't appear to be any different then the version in 3.4.2. I've looked at SVN (where I can diff the files) and lapacke_config.h has definately not changed on trunk. lapacke.h has changed, but the changes don't appear to have anything to do with this issues (looks mostly like some additional functions have been added).

Re: lapacke.h: template with C linkage error [patch included

PostPosted: Thu Apr 04, 2013 1:14 am
by Matt Phillips
Just checking in to say that I just got version 1387 off svn and I'm having the same problem (as with 3.4.2), "template with C linkage", associated with both complex and sstream stl files.

Re: lapacke.h: template with C linkage error [patch included

PostPosted: Thu Apr 04, 2013 1:23 am
by admin
Could you please check version 1388 ;-)
Thank you all and sorry for the mess...

Re: lapacke.h: template with C linkage error [patch included

PostPosted: Thu Apr 04, 2013 1:30 am
by Matt Phillips
Ha! Just put

Code: Select all
#include <complex.h>
#define lapack_complex_float    float _Complex
#define lapack_complex_double   double _Complex

prior to

Code: Select all
#include <lapacke.h>

in the calling code. This does require the user to make sure that the definitions don't get out of sync as LAPACK continues to be developed, so solving this within the lapacke code itself would be great.

Re: lapacke.h: template with C linkage error [patch included

PostPosted: Thu May 30, 2013 5:11 pm
by robzumwalt
Is there a planned release date that will include this fix? I'd like to use this with Openblas.