我的代码遇到了一个非常奇怪的问题。我试着用碰和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的内容写入文件时,它似乎也不会出现
发布于 2021-05-16 01:28:45
事实证明Barmar是对的。我包含了一个已经存在math.h的目录,因此导致不包含libc目录。对于那些与七角形语言有相同问题的人来说,有问题的是-I$(heptc -where)/c/。谢谢你的帮助。
发布于 2021-05-20 19:28:22
正如@Barmar所评论的那样,问题是在$(heptc -where)/c/中已经定义了一个math.h头文件,它并没有实现你想要在这个例子中使用的函数。
考虑到它是用Heptagon编译的,我建议从$(heptc -where)/c/复制唯一真正有用的文件,这个文件是pervasives.h,你有你的init_twiddle.c,既然你是用-I.编译的,那么它就会编译得很好。
https://stackoverflow.com/questions/67541923
复制相似问题