为什么说sin未定义?

软件和网站开发以及相关技术探讨
回复
VisionMiracle
帖子: 42
注册时间: 2006-08-20 8:20

为什么说sin未定义?

#1

帖子 VisionMiracle » 2006-08-29 9:56

用的Anjuta
明明在函数库设定里把C标准库选上了阿
fteye
帖子: 201
注册时间: 2005-11-18 20:52

#2

帖子 fteye » 2006-08-29 10:26

应该选上cmath库吧
#include<cmath>
头像
ectotherm
帖子: 225
注册时间: 2006-05-23 13:35
联系:

#3

帖子 ectotherm » 2006-08-29 11:16

如果包含 cmath,sin 在 std 中,如果是 math.h 就没有名称空间了。用哪个取决于于你是写 c 还是 c++。
VisionMiracle
帖子: 42
注册时间: 2006-08-20 8:20

#4

帖子 VisionMiracle » 2006-08-29 11:31

ComputeCoef.c:2:17: error: cmath: No such file or directory
ComputeCoef.c: 在函数 ‘main’ 中:
ComputeCoef.c:33: 警告: 隐式声明与内建函数 ‘sin’ 不兼容
头像
ectotherm
帖子: 225
注册时间: 2006-05-23 13:35
联系:

#5

帖子 ectotherm » 2006-08-29 11:35

晚上回去看看,我这里只有 mingw,ps 把你的整个代码贴上来看看。
fteye
帖子: 201
注册时间: 2005-11-18 20:52

#6

帖子 fteye » 2006-08-29 12:05

#include<math.h>
VisionMiracle
帖子: 42
注册时间: 2006-08-20 8:20

#7

帖子 VisionMiracle » 2006-08-29 12:10

#include <stdio.h>
#include <cmath>

#define Resolution 512
#define R Resolution
#define TubeNum 512
#define TN TubeNum
#define ProjNum 256
#define PN ProjNum
#define PixelSize 1
#define PS PixelSize
#define RelativeTubeSpace 1 /* Compared to PixelSize */
#define RTS RelativeTubeSpace
#define AbsoluteTubeSpace PS*RTS
#define ATS AbsoluteTubeSpace
#define ImageWidth PS*R
#define IW ImageWidth

#define pi 3.1415926

main ()
{
int i1;
for (i1=1;i1<=PN;i1++)
{
double theta=(pi/PN)*(i1-1);
int i2;
for (i2=1;i2<=TN;i2++)
{
double t=(i2-(1+TN)/2)*RTS;
double j2;
if (theta==0)
j2=sin(t)+R/2+1;


printf("\n");
}
}
}
头像
ectotherm
帖子: 225
注册时间: 2006-05-23 13:35
联系:

#8

帖子 ectotherm » 2006-08-29 12:41

我用 mingw 3.4.2 编译什么问题都没有啊,ps 你那个代码是谁写的,糟糕得一塌糊涂。
上次由 ectotherm 在 2006-08-29 12:55,总共编辑 1 次。
fteye
帖子: 201
注册时间: 2005-11-18 20:52

#9

帖子 fteye » 2006-08-29 12:55

也许是anjuta的链接库设置的问题
VisionMiracle
帖子: 42
注册时间: 2006-08-20 8:20

#10

帖子 VisionMiracle » 2006-08-31 8:53

ectotherm 写了:我用 mingw 3.4.2 编译什么问题都没有啊,ps 你那个代码是谁写的,糟糕得一塌糊涂。
不好意思,我写的,编程很烂,C更是好久没用,糟糕之处还请指正
头像
ectotherm
帖子: 225
注册时间: 2006-05-23 13:35
联系:

#11

帖子 ectotherm » 2006-08-31 9:03

简单地说 C++ 不是 C,避免使用 #define,还有声明 main() 实际上是 int main() 不写会默认成 int,但是这个在 C99 还是 C89 中已经被淘汰了。

先指出两点,其它的要更详细的了。
头像
lysting
帖子: 41
注册时间: 2006-07-13 11:43
来自: 深圳
联系:

#12

帖子 lysting » 2006-09-01 12:16

哈哈~~~我想,是php把缩格给过滤掉了,所以才这么乱,我也用php写过论坛,也曾经干过这样的坏事 :(
不过楼主还要区分有.h和无.h的区别,namespace ,for循环里的 ++, 还有代码风格......
头像
ectotherm
帖子: 225
注册时间: 2006-05-23 13:35
联系:

#13

帖子 ectotherm » 2006-09-01 13:10

...缩进对上面的代码是小得不能再小的问题,那个问题用 astyle 格式化下就解决了。
jiazufei
帖子: 5
注册时间: 2008-06-19 13:42

#14

帖子 jiazufei » 2008-06-26 11:10

数学标准库在 /usr/lib/libm.a里,所以这样编译
gcc -Wall *.c /usr/lib/libm.a -o *
回复