This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libstdc++ problems with math functions - fixinc or stdc++ problem?


Hi.

I encountered the same thing with my recent QNX Neutrino patch.
I'm not sure if I solved it correctly, because no-one has responded
to my posting yet, but I think the libstdc++ header files make bad 
assumptions that the OS's headers have 'acos' and friends defined as
macros, and so the GNU headers then go ahead and undefine and replace
them with inline functions.

Can anyone please comment on the correctness (or badness) of the below
approach to solving this?

Thanks.
GP

(Edited from libstdc++-v3/include/c/std_cmath.h)
I changed things from:

 // Get rid of those macros defined in <math.h> in lieu of real functions.
 #undef abs   // <--- This is one I had trouble with.
 #undef div
 // etc...
 
 namespace std
 {
   inline double
   abs(double __x)
   { return __builtin_fabs(__x); }
 
   inline float
   abs(float __x)
   { return __builtin_fabsf(__x); }
 
   inline long double
   abs(long double __x)
   { return __builtin_fabsl(__x); }
 }

to:

 // Get rid of those macros defined in <math.h> in lieu of real functions.
 #undef div
 // etc...

 namespace std
 {
 // Only undefine and replace abs if it is a macro
 #ifdef abs
 #undef abs
   inline double
   abs(double __x)
   { return __builtin_fabs(__x); }
 
   inline float
   abs(float __x)
   { return __builtin_fabsf(__x); }
 
   inline long double
   abs(long double __x)
   { return __builtin_fabsl(__x); }
 #endif
 }



Kean Johnston <jkj at sco dot com> said:

> All,
> 
> I now have gcc3.3 almost bootstrapping on OSR5. In
> fact it gets all the compiler stuff done, but its
> now breaking in libstdc++. I get a slew of errors
> along the lines on:
> /path/libstdc++-v3/include/cmath.h:105: error: 'acos' is
>    already declared in this scope
> /path/libstdc++-v3/include/cmath.h: In function 'long
>    double std::acos(long double)':
> /path/libstdc++-v3/include/cmath.h:109: error: 'long double
>    std::acos(long double) conflicts with previous using declaration
> 'long
>    double acos(long double)'
> 
> A quick peek in math.h shows that all the functions that error out are
> already defined there. So I edited the "fixed" math.h in the
> gcc/includes
> directory to comment out all the C++ definitions (by surrounding them
> with #ifndef __GNUC__). My question is, is this a problem with fixinc,
> and should I fix that, or is it a problem with libstdc++?
> 
> In the particular example cited above, the line in math.h that gets
> commented out is:
> inline long double acos(long double __1){return acosl(__1); }
> 
> I am C++-impaired so I don't even know where to begin.
> 
> Advice welcomed.
> 
> Kean
> 
> 



-- 




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]