Chinaunix

标题: 为什么编译连接不成功?!! [打印本页]

作者: xman0017    时间: 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]$
作者: hutuworm    时间: 2005-06-15 11:14
标题: 为什么编译连接不成功?!!
检查程序
把函数前的下划线去掉
作者: ssffzz1    时间: 2005-06-15 14:54
标题: 为什么编译连接不成功?!!
哥哥,是不是有个库没有include.
作者: xman0017    时间: 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                              

郁闷拉




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2