Issue
Couple days ago it was working fine, but trying to use again today, my code editor cannot find sincos anymore and GCC throws me a warning that it cannot find sincos when compiling.
Here's the code:
// file: main.c
#include <math.h>
int main() {
double sin, cos;
sincos(0.0, &sin, &cos);
return 0;
}
Using gcc:
$ gcc main.c -lm
x.c: In function ‘main’:
x.c:5:2: warning: implicit declaration of function ‘sincos’ [-Wimplicit-function-declaration]
5 | sincos(0.0, &sin, &cos);
| ^~~~~~
x.c:5:2: warning: incompatible implicit declaration of built-in function ‘sincos’
x.c:2:1: note: include ‘<math.h>’ or provide a declaration of ‘sincos’
1 | #include <math.h>
+++ |+#include <math.h>
2 |
It says I should include math.h yet I do. It says it can't find sincos yet it compiles and runs fine. I'm just annoyed by those warnings. Anyone knows what's wrong?
Solution
Add the following to the top of the file to enable the gnu extension:
#define _GNU_SOURCE
#include <math.h>
This will prevent the warnings. Note that this is a glibc
extension and not part of the C standard.
Answered By - Tom Karzes Answer Checked By - Mildred Charles (PHPFixing Admin)