LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1693|回复: 17

No such file or directory !!

[复制链接]
发表于 2004-10-15 00:06:07 | 显示全部楼层 |阅读模式
  1. #include<sys/types.h>
  2. #include<dirent.h>
  3. #include "ourhdr.h"
  4.                                                                                 
  5. int
  6. main(int argc,char *argv[])
  7. {
  8.   DIR *dp;
  9.   struct dirent *dirp;
  10.   if (argc != 2)
  11.     err_quit("a single argument (the directory name) is required");
  12.   if ((dp = opendir(argv[1])) == NULL)
  13.     err_sys("can't open %s",argv[1]);
  14.   while ((dirp = readdir(dp)) != NULL)
  15.     printf("%s\n",dirp->d_name);
  16.   closedir(dp);
  17.   exit(0);
  18. }
复制代码



# gcc -Wall shell.c shell
gcc: shell: No such file or directory


# gcc -Wall shell.c shell *
gcc: shell: No such file or directory
myerror.c: In function `err_msg':
myerror.c:57: warning: implicit declaration of function `va_stat'


怎么会这样 ? 该怎么办?
发表于 2004-10-15 00:07:30 | 显示全部楼层
gcc -shell.c -o shell
 楼主| 发表于 2004-10-15 00:09:13 | 显示全部楼层
# gcc shell.c -o shell
/tmp/cc4f5Eg4.o(.text+0x1f): In function `main':
: undefined reference to `err_quit'
/tmp/cc4f5Eg4.o(.text+0x53): In function `main':
: undefined reference to `err_sys'
collect2: ld returned 1 exit status

这个程序你们编译得过吗 ?


ourhdr.h头文件在这里http://www.linuxsir.cn/forum.php?mod=viewthread&tid=145394
发表于 2004-10-15 00:15:15 | 显示全部楼层
err_quit
err_sys
两个函数你编译了吗
 楼主| 发表于 2004-10-15 00:16:06 | 显示全部楼层
这两个函数如何编译 ??? 如何使用 ?谢谢
发表于 2004-10-15 00:20:35 | 显示全部楼层
另外还有一个错误处理文件,你可以把它先编译出来,比如我把它命名为myerror.c:
用gcc -c myerror.c编译得到myerror.o

你这次这样用:
gcc shell.c myerror.o -o shell
 楼主| 发表于 2004-10-15 00:21:34 | 显示全部楼层
root:  /stmp  # ls
love.c  myerror.c  myerror.o  reading.txt  shell.c  Unix C
root:  /stmp  # gcc shell.c  myerror.o -o shell
myerror.o(.text+0x7e): In function `err_msg':
: undefined reference to `va_stat'
collect2: ld returned 1 exit status
root:  /stmp  #
发表于 2004-10-15 00:26:08 | 显示全部楼层
void
err_msg(const char *fmt, ...)
{
  va_list ap;

  va_stat(ap, fmt); ////这里可能敲错了吧,你改成start试试
  err_doit(0, fmt, ap);
  va_end(ap);
  return;
}
 楼主| 发表于 2004-10-15 00:30:51 | 显示全部楼层
./shell
a single argument (the directory name) is required


这样是不是成功了,, !

问一下之前的问题,之前错误时,gcc -c myerror.c -o myerror.o怎么没显示错误呢 ?? 可以告诉我吗,谢谢你
发表于 2004-10-15 02:33:05 | 显示全部楼层
最初由 shell 发表
./shell
a single argument (the directory name) is required


这样是不是成功了,, !

问一下之前的问题,之前错误时,gcc -c myerror.c -o myerror.o怎么没显示错误呢 ?? 可以告诉我吗,谢谢你


这样编译已经成功了,看英文提示,还有源代码,这个程序运行要求有一个参数,即一个目录名,程序的作用是显示某目录下的所有文件及目录,就像ls命令一样,所以这样执行:
$./shell 目录路径
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表