gcc4: OpenMP vs. <math.h>

Yaakov (Cygwin/X) yselkowitz@users.sourceforge.net
Fri Jan 8 08:09:00 GMT 2010


POSIX allows for <math.h> functions to also be defined as macros. 
Currently, only log2 and log2f are so defined.

These macros pose problems with a few projects which define their own 
static/inline/template log2() (off the top of my head, I can think of 2: 
the CRAN rgl module, and OpenCV; both are C++).  Of course, those can be 
fixed with an #undef log2 after the #include's.

However, I just encountered tonight a much larger conflict: OpenMP/C++ 
and <math.h> are incompatible.  STC attached:

$ g++ -D_GLIBCXX_PARALLEL -fopenmp openmp.cxx -lgomp
In file included from 
/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/parallel/algobase.h:46,
                  from 
/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/stl_algobase.h:1137,
                  from 
/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/char_traits.h:46,
                  from /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/ios:46,
                  from 
/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/ostream:45,
                  from 
/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/iostream:45,
                  from openmp.cxx:7:
/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/parallel/base.h:112: 
error: expected `)' before ‘/’ token

It gets even worse if you #include <algorithm> as well, and no, it 
doesn't help to #include <cmath>, although moving the math include after 
all other includes does work.

I see two possible solutions:

1) Make the log2 macros dependent on #ifndef __cplusplus;
2) Make the parallel/* headers #undef log2 and log2f.

Thoughts?


Yaakov
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: openmp.cxx
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100108/3ad17827/attachment.cxx>
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list