Hello,
I wrote a C program that relies on the sqrtf function to calculate the square root of a float, so I check if the macro _POSIX_C_SOURCE is defined before including any header. The problem is that the macro is defined (its value is 200809L) and it refuses to compile. Here's an example:
Code:
#ifdef _POSIX_C_SOURCE
#include <stdio.h>
#include <math.h>
#endif
int main(void) {
float foo = sqrtf(3.5);
printf("%f\n", foo);
return 0;
}
And this is what I get when trying to compile it:
Code:
$ gcc -std=c99 -lmath -o test test.c
test.c: In function 'main':
test.c:7:17: warning: implicit declaration of function 'sqrtf' [-Wimplicit-function-declaration]
float foo = sqrtf(3.5);
^~~~~
test.c:7:17: warning: incompatible implicit declaration of built-in function 'sqrtf'
test.c:7:17: note: include '<math.h>' or provide a declaration of 'sqrtf'
test.c:8:5: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
printf("%g\n", foo);
^~~~~~
test.c:8:5: warning: incompatible implicit declaration of built-in function 'printf'
test.c:8:5: note: include '<stdio.h>' or provide a declaration of 'printf'
/usr/bin/ld: cannot find -lmath
collect2: error: ld returned 1 exit status
Why aren't the headers included?
Thanks in advance.