【发布时间】:2023-03-16 12:49:01
【问题描述】:
我的代码遇到了一个非常奇怪的问题。 我尝试使用 clang 和 gcc,两者都告诉我同样的事情
init_twiddle.c:12:10: warning: implicitly declaring library function 'cosf' with type 'float (float)' [-Wimplicit-function-declaration]
.re = cosf(primitive_root*i) ,
^
init_twiddle.c:12:10: note: include the header <math.h> or explicitly provide a declaration for 'cosf'
init_twiddle.c:13:10: warning: implicitly declaring library function 'sinf' with type 'float (float)' [-Wimplicit-function-declaration]
.im = sinf(primitive_root*i)
^
init_twiddle.c:13:10: note: include the header <math.h> or explicitly provide a declaration for 'sinf'
2 warnings generated.
代码:
// file: init_twiddle.c
#include "complex.h"
#include <math.h>
void init_twiddle1024(Complex__complex* twiddle) {
int i,span ;
// Init the twiddles
for(span=1;span<=512;span<<=1) {
float primitive_root = -Complex__pi/span ;
for(i=0;i<span;i++) {
Complex__complex t =
{
.re = cosf(primitive_root*i) ,
.im = sinf(primitive_root*i)
} ;
twiddle[span+i] = t ;
}
}
}
// file: complex.h
#ifndef COMPLEX_H
#define COMPLEX_H
#include "stdbool.h"
#include "assert.h"
//#include "pervasives.h"
typedef struct Complex__complex {
float re;
float im;
} Complex__complex;
static const float Complex__pi = 3.141593;
#endif // COMPLEX_H
我用来编译的命令:
gcc -I. -I$(heptc -where)/c/ -std=c99 -c init_twiddle.c
我正在使用一些奇怪的编程语言来解释所有包含的目录。
有人知道我为什么会收到这些错误吗?
PS:请注意,这不是链接器问题,而是编译时的问题。 当我手动将 complex.h 的内容写入文件时,它似乎也没有出现
【问题讨论】:
-
我们需要足够的代码来重现错误。如果您可以在没有
complex.h的情况下复制它,请编辑您的问题。如果没有,请包含该代码。 -
您有自己的
math.h文件吗?您的-I选项提供了在系统版本之前搜索<math.h>的目录。 -
是的,你是对的,我使用的语言定义了它自己的 math.h,我将它包含在 -I$(heptc -where)/c/ 中,非常感谢,我想我可以解决这个问题问题知道(虽然不是因为这不是我的math.h)
-
是的,您的代码在 Ubuntu 上的系统
<math.h>上运行良好,所以它必须是您自定义的math.h。 -
非常感谢您解决了我的问题,现在我只需要找到如何在不删除 -I 的情况下包含正确的 math.h 即可。另外我对堆栈溢出很陌生,我应该如何将此问题标记为已解决?