免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6455 | 回复: 8
打印 上一主题 下一主题

[C] undefined reference to "ftime" [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-25 14:00 |只看该作者 |倒序浏览
代码如下:
/* algo1-1.c 计算1-1/x+1/x*x… */
#include<stdio.h>
#include<sys/timeb.h>
void main()
{
   struct timeb t1,t2;
   long t;
   double x,sum=1,sum1;
   int i,j,n;
   printf("请输入x n:");
   scanf("%lf%d",&x,&n);
   ftime(&t1); /* 求得当前时间 */
   for(i=1;i<=n;i++)
   {
     sum1=1;
     for(j=1;j<=i;j++)
       sum1=-sum1/x;
     sum+=sum1;
   }
   ftime(&t2); /* 求得当前时间 */
   t=(t2.time-t1.time)*1000+(t2.millitm-t1.millitm); /* 计算时间差 */
   printf("sum=%lf 用时%ld毫秒\n",sum,t);
}
在freebsd下编译出的错误
gcc test.c

论坛徽章:
0
2 [报告]
发表于 2008-09-25 14:05 |只看该作者

回复 #2 j1111011 的帖子

怎么包含库,指点下啊。。。。

论坛徽章:
0
3 [报告]
发表于 2008-09-25 14:14 |只看该作者

回复 #4 j1111011 的帖子

#include<sys/timeb.h>
这个里面就有ftime的定义

论坛徽章:
0
4 [报告]
发表于 2008-09-25 14:15 |只看该作者

回复 #4 j1111011 的帖子

楼主不是include<sys/timeb.h>了吗?
在我这里编译正常貌似,我这是debian

[ 本帖最后由 madoldman 于 2008-9-25 14:17 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2008-09-25 14:26 |只看该作者
g++ -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.4/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix


我这可以编译过去Linux 2.6.9

论坛徽章:
0
6 [报告]
发表于 2008-09-25 14:27 |只看该作者
ftime是标准库里的函数阿

论坛徽章:
0
7 [报告]
发表于 2008-09-25 14:39 |只看该作者

回复 #7 j1111011 的帖子

好象是少个libcompat

论坛徽章:
0
8 [报告]
发表于 2008-09-25 15:57 |只看该作者
libcompat??
ftime这个函数不是应该直接就在libc.so里面吗?

论坛徽章:
0
9 [报告]
发表于 2008-09-28 14:47 |只看该作者

回复 #11 madoldman 的帖子

1 /*
      2  * Copyright (c) 1994 Christopher G. Demetriou
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *      This product includes software developed by Christopher G. Demetriou.
     16  * 4. The name of the author may not be used to endorse or promote products
     17  *    derived from this software without specific prior written permission
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  *
     30  * $FreeBSD: src/lib/libcompat/4.1/ftime.c,v 1.5 1999/08/28 00:04:12 peter Exp $

     31  * $DragonFly: src/lib/libcompat/4.1/ftime.c,v 1.2 2003/06/17 04:26:48 dillon Exp $
     32  */
     33
     34 #include <sys/types.h>
     35 #include <sys/time.h>
     36 #include <sys/timeb.h>
     37
     38 int
     39 ftime(tbp)
     40         struct timeb *tbp;
     41 {
     42         struct timezone tz;
     43         struct timeval t;
     44
     45         if (gettimeofday(&t, &tz) < 0)
     46                 return (-1);
     47         tbp->millitm = t.tv_usec / 1000;
     48         tbp->time = t.tv_sec;
     49         tbp->timezone = tz.tz_minuteswest;
     50         tbp->dstflag = tz.tz_dsttime;
     51
     52         return (0);
     53 }


我也不清楚,看到这么个东西,感觉可能是它的原因
不过还没有解决,我比较菜,所以以为可能是系统没弄好,于是在unix-center的远程机器上实验了一下,也是同样的错误,于是就放弃了。。

[ 本帖最后由 onmeiei 于 2008-9-28 14:49 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP