This is the mail archive of the
gsl-discuss@sourceware.cygnus.com
mailing list for the GSL project.
Re: extern "C" for C++
- To: Vanroose <vanroose at ruca dot ua dot ac dot be>
- Subject: Re: extern "C" for C++
- From: Brian Gough <bjg at network-theory dot co dot uk>
- Date: Thu, 4 May 2000 10:25:51 +0100 (BST)
- Cc: gsl-discuss at sourceware dot cygnus dot com
- References: <3911301A.7ED26BE9@ruca.ua.ac.be>
Yes, that does seem to be a problem with the gsl-0.5 header files. We
have switched to using extern "C" wrapped directly around the
declarations inside the GSL header files now, which will avoid that
conflict in future.
Until the next version is released you could try putting #include
<math.h> in your own program before the extern "C". This should stop
math.h being included a second time inside the extern "C" part.
Vanroose writes:
> Dear GSL-users,
>
> As discussed in the november archives of this mailing list I
> have to include a 'extern "C" ' before I include the GSL headerfile
> when I want to use a gsl-function in C++.
>
> So I added to my code
>
> #ifdef __cplusplus
> extern "C" {
> #endif
> #include <gsl_sf_result.h>
> #include <gsl_sf_coulomb.h>
> #include <gsl_sf_laguerre.h>
> #include <gsl_sf_gamma.h>
> #include <gsl_sf_erf.h>
> #include <gsl_integration.h>
> #ifdef __cplusplus
> }
> #endif
>
>
> This results into problems in math.h with function
> overloading
>
> gcc -c -fpic potential.cc -I/xopt/python1.5/include/python1.5
> -I/home/edp/vanroose/archief/vanroose/Python-1.5.2/Numerical-14/Include/
> -I/home/edp/vanroose/include/gsl/
> In file included from /home/edp/vanroose/include/gsl/gsl_math.h:3,
> from
> /home/edp/vanroose/include/gsl/gsl_integration.h:4,
> from potential.cc:9:
> /xopt/gnu/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1/include/math.h: In
> function `double pow(double, int)':
> /xopt/gnu/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1/include/math.h:74:
> declaration of C function `double pow(double, int)' conflicts with
> /xopt/gnu/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1/include/math.h:71:
> previous declaration `double pow(double, double)' here
> /xopt/gnu/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1/include/math.h: In
> function `double pow(double, int)':
> /xopt/gnu/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1/include/math.h:75:
> warning: `double' used for argument 2 of `pow(double, int)'
> make: *** [potentialC] Error 1
>
>
> When I look to the math.h code that the compiler refers to
>
> #ifdef _INCLUDE_HPUX_SOURCE
> extern double log2(double);
> #endif
> extern double modf(double, double *);
> extern double pow(double, double);
> # ifdef __cplusplus
> }
> inline double pow(double __d,int __expon) {
> return pow(__d,(double)__expon);
> }
> extern "C" {
> #else
> # endif
>
> It seems that when math.h is included the __cplusplus
> variable is still set but due to the extern "C" derictive the code is
> compiled as C. Or am I wrong??
>
>