求教:gcc 编译时候 sqrt 函数警告的问题

软件和网站开发以及相关技术探讨
回复
头像
wnryp
帖子: 35
注册时间: 2008-11-11 16:51

求教:gcc 编译时候 sqrt 函数警告的问题

#1

帖子 wnryp » 2011-03-17 11:36

代码:

代码: 全选

  #include<stdio.h>
  #include<math.h>
  int main(void)
  {
      float a,b,c,s,area;
      scanf("%f,%f,%f",&a,&b,&c);
      s=1.0/2*(a+b+c);
      area=sqrt(s*(s-a)*(s-b)*(s-c));
      printf("a=%7.2f,b=%7.2f,c=%7.2f,s=%7.2f\n",a,b,c,s);
      printf("area=%7.2f\n",area);
      return 0;
  }   
编译命令:

代码: 全选

gcc -Wall test016_01.c -lm -o test016_01
编译结果:

代码: 全选

test016_01.c: In function ‘main’:
test016_01.c:16: warning: implicit declaration of function ‘sqrt’
test016_01.c:16: warning: incompatible implicit declaration of built-in function ‘sqrt’

Press ENTER or type command to continue
不知为什么会出现这个警告,去查了下,都说不是没有包含math.h 就是编译时没有-lm选项,但是我都有阿,为什么还会出现这种警告呢?谢谢。。
上次由 wnryp 在 2011-03-17 12:57,总共编辑 1 次。
海到无边天作岸,山登绝顶我为峰!
头像
wnryp
帖子: 35
注册时间: 2008-11-11 16:51

Re: 求教:gcc 编译时候 sqrt 问题

#2

帖子 wnryp » 2011-03-17 12:48

pocoyo 写了:我的正常啊。
:em21 为什么我的不正常呐~~纳闷至极阿~~
海到无边天作岸,山登绝顶我为峰!
头像
wnryp
帖子: 35
注册时间: 2008-11-11 16:51

Re: 求教:gcc 编译时候 sqrt 函数警告的问题

#3

帖子 wnryp » 2011-03-17 14:01

:em06 好了,一个超级低级无趣的错误。。。。。。。。。 :em06

我首先是建立的 vim test016.c

后来代码写好后 :w test016_01.c
另存了下,以为当前编辑的就是test016_01.c了,
可没想到编辑的还是test016.c
以至于位后来做的编辑只保存在了test016.c 上,
而test016_01.c没有改动,而编译的时候确实编译的test016_01.c
所以喽~‵‵‵~~ :em06 :em06
海到无边天作岸,山登绝顶我为峰!
回复