creal and cimag problems with Clang 3.4

562 views Asked by At

I am compiling a library with Petsc using Clang 3.4 and get:

error: use of undeclared identifier 'creal'

it follows from the following define:

petscmath.h:121:38: note: expanded from macro 'PetscRealPartComplex'
#define PetscRealPartComplex(a)      creal(a)

the only relevant info i can find is this, i don't know if this is something compiler-specific and some libraries are missing or i have some problems with Petsc.

I tried using `cimag()' as it is in a small test file, but i can't compile it with neither clang3.4 nor gcc4.8.

Anyone has any ideas what is happening. Google does not show any similar topics...

EDIT:

so here is a simple example:

#include <complex.h>
int main ()
{
   double complex z;
   double cc = cimag(z);
}

it does compile with Gcc4.8 (from macports): g++-mp-4.8 main.cc -o main

however in c11 mode it does not : g++-mp-4.8 -std=c++11 main.cc -o main:

expected initializer before 'z' double complex z;

clang does not compile it in either cases and produce the same error as above.

1

There are 1 answers

2
AudioBubble On BEST ANSWER

Reference: http://pubs.opengroup.org/onlinepubs/7999959899/basedefs/complex.h.html

The header shall define the following macros:

complex

    Expands to _Complex.

Reference: http://en.cppreference.com/w/c/numeric/complex

If the macro constant STDC_NO_COMPLEX(C11) is defined by the compiler, the header and all of the names listed here are not provided.

Note that I get the same results when specifying -std=c++11 with GCC, but not -x c -std=c11. YMMV.