Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 21994

CMPLX Yields Undefined Symbol with GCC

$
0
0

I'm trying to hunt down a problem using complex literals when compiling with GCC. Consider the following

#include <stdio.h>
#include <complex.h>

int main(void)
{
    double complex z = CMPLX(0.0, -1.0);
    printf("z = %.1f%+.1fi\n", creal(z), cimag(z));
    return 0;
}

(slightly modified from the reference page). If I compile with Clang, it works as expected. However, if I use GCC I get an undefined reference error

gcc -std=c11 mwe.c
mwe.c: 6:24 warning: implicit declaration of function 'CMPLX' ...
mwe.c:(...) undefined reference to `CMPLX'

I have tried this with GCC 4.7 and 7.2 on Linux and GCC 9 on MacOS. The error messages change, but the net result remains the same. Reviewing the reference for CMPLX, this should be valid C11. Based on this answer and this post, it appears like GCC accepted this construct before.

My bottom line question is: Why can't I use CMPLX with GCC?


Viewing all articles
Browse latest Browse all 21994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>