免费注册 查看新帖 |

Chinaunix

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

为什么编译连接不成功?!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-15 10:24 |只看该作者 |倒序浏览
环境 : REDHAT 7.2下
编译连接失败了!!
信息如下:

[test@xOS test]$ cat t.c
#include "stdio.h"

FILE *stream, *stream2;

int main( void )
{
   int numclosed;

   /* Open for read (will fail if file "data" does not exist) */
   if( (stream  = fopen( "data", "r" )) == NULL )
      printf( "The file 'data' was not opened\n" );
   else
      printf( "The file 'data' was opened\n" );

   /* Open for write */
   if( (stream2 = fopen( "data2", "w+" )) == NULL )
      printf( "The file 'data2' was not opened\n" );
   else
      printf( "The file 'data2' was opened\n" );

   /* Close stream */
   if( fclose( stream ) )
      printf( "The file 'data' was not closed\n" );

   /* All other files are closed: */
   numclosed = _fcloseall( );
   printf( "Number of files closed by _fcloseall: %u\n", numclosed );
}

[test@xOS test]$ gcc t.c
/tmp/ccfuoEhc.o: In function `main':
/tmp/ccfuoEhc.o(.text+0x15): undefined reference to `__fopen'
/tmp/ccfuoEhc.o(.text+0x5f): undefined reference to `__fopen'
/tmp/ccfuoEhc.o(.text+0xc0): undefined reference to `_fcloseall'
collect2: ld returned 1 exit status
[test@xOS test]$

论坛徽章:
0
2 [报告]
发表于 2005-06-15 11:14 |只看该作者

为什么编译连接不成功?!!

检查程序
把函数前的下划线去掉

论坛徽章:
5
IT运维版块每日发帖之星
日期:2015-08-06 06:20:00IT运维版块每日发帖之星
日期:2015-08-10 06:20:00IT运维版块每日发帖之星
日期:2015-08-23 06:20:00IT运维版块每日发帖之星
日期:2015-08-24 06:20:00IT运维版块每日发帖之星
日期:2015-11-12 06:20:00
3 [报告]
发表于 2005-06-15 14:54 |只看该作者

为什么编译连接不成功?!!

哥哥,是不是有个库没有include.

论坛徽章:
0
4 [报告]
发表于 2005-06-16 15:13 |只看该作者

为什么编译连接不成功?!!

哪位大哥试一试,看如何才能编译、连接通过??
我用下面方法还是错误!!


[root@xOS root]# gcc t.c -lc                                      
/tmp/ccKiFn0B.o: In function `main':                              
/tmp/ccKiFn0B.o(.text+0x15): undefined reference to `__fopen'     
/tmp/ccKiFn0B.o(.text+0x5f): undefined reference to `__fopen'     
collect2: ld returned 1 exit status                              
[root@xOS root]# gcc t.c -L/usr/lib -lc                           
/tmp/ccIsRPCv.o: In function `main':                              
/tmp/ccIsRPCv.o(.text+0x15): undefined reference to `__fopen'     
/tmp/ccIsRPCv.o(.text+0x5f): undefined reference to `__fopen'     
collect2: ld returned 1 exit status                              

郁闷拉
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP