c - 辛科斯去哪儿了? (海湾合作委员会c)

标签 c gcc warnings math.h

几天前它工作得很好,但是今天再次尝试使用时,我的代码编辑器再也找不到 sincos,GCC 向我发出警告,说它在编译时找不到 sincos。

代码如下:

// file: main.c 

#include <math.h>                                                                                                  
int main() {                                                                                                                         
    double sin, cos;                                                                                                     
    sincos(0.0, &sin, &cos);                                                                                             
    return 0;                                                                                                    
}        

使用海湾合作委员会:

$ 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 |

它说我应该包含 math.h 但我还是这么做了。 它说它找不到 sincos,但它编译并运行良好。我只是对这些警告感到恼火。有谁知道出了什么问题吗?

最佳答案

将以下内容添加到文件顶部以启用 gnu 扩展:

#define _GNU_SOURCE
#include <math.h>

这将防止出现警告。请注意,这是一个 glibc 扩展,而不是 C 标准的一部分。

关于c - 辛科斯去哪儿了? (海湾合作委员会c),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61451008/

相关文章:

c - 包含 strptime() 函数声明的问题

c - 为什么省略参数的显式 'int' 类型有时无法在 gcc 中编译?

c++ - 我如何检查有多少特定的 g++ 版本支持 C++11

c++ - ThreadSanitizer FATAL 运行时异常

Android构建警告将新ns映射到旧ns

c - 如何解决 "control reaches end of non-void function"警告?

python - 如何将多个变量从Python脚本传递到C shell脚本

c - 在 C 中存储包含整数和字符的文件内容

c - fork() 如何停止创建子进程?

c - 错误: invalid operands to binary < (have 'float *' and 'double' )