extern "C" for C++

Vanroose vanroose@ruca.ua.ac.be
Thu May 4 01:09:00 GMT 2000


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??
 
 





More information about the Gsl-discuss mailing list