LinuxSir.cn,穿越时空的Linuxsir!

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

undefined reference to `err_quit' 是啥错误?

[复制链接]
发表于 2004-5-10 13:15:52 | 显示全部楼层 |阅读模式
最近正要研习<Advanced Programming in the UNIX Environment>,下载了代码,可就是在我的RH8.0上编译通不过.

比如这个文件:myls.c

#include <sys/types.h>
#include <dirent.h>
#include "ourhdr.h"

int main(int argc, char *argv[])
{
        DIR                             *dp;
        struct dirent   *dirp;

        if ( argc != 2 )
                err_quit("a single argument (the directory name)"
                                 " is required");
        if ( (dp = opendir(argv[1])) == NULL)
                err_sys("can't open %s", argv[1]);

        while ( (dirp = readdir(dp)) != NULL)
                printf("%s\n", dirp->d_name);

        closedir(dp);
        exit(0);
}

其中的ourhdr.h是书中为方便而给定的统一的头文件,其中内容含有

void    err_dump(const char *, ...);    /* {App misc_source} */
void    err_msg(const char *, ...);
void    err_quit(const char *, ...);
void    err_ret(const char *, ...);
void    err_sys(const char *, ...);

我不知在函数声明的参数中写省略号对不对(应该不对吧),但至少应该算"声明"了吧.

可是当我编译前面那个myls.c文件时:

gcc myls.c

却出现如下错误提示信息:

/tmp/ccPfIjbp.o: In function `main':
/tmp/ccPfIjbp.o(.text+0x1f): undefined reference to `err_quit'
/tmp/ccPfIjbp.o(.text+0x53): undefined reference to `err_sys'
collect2: ld returned 1 exit status

我不知哪位大哥实际练习过<Advanced Programming in the UNIX Environment>的代码,请指教这到底是怎么回事,还需要改写哪些地方或设置.谢谢!!
发表于 2004-5-10 18:48:03 | 显示全部楼层
在书的附录B中有这些函数的代码,自己加上。
 楼主| 发表于 2004-5-11 17:16:21 | 显示全部楼层
哦,谢谢kj501。我知道了,所谓void err_dump(const char *, ...)就是ANSI C里的variable-length argument list facility。这样declare本身是没错的。
 楼主| 发表于 2004-5-11 17:18:40 | 显示全部楼层
原来是我没按照说明进行编译,其实在makefile里都写好了依赖关系,而我却单单地输了个gcc myls.c,当然会找不到那个error.c。我应当make myls,这样就对了,呵呵。
发表于 2008-12-29 15:22:20 | 显示全部楼层
都快2009年了!不知道楼主现在的unix环境编程学到什么程度了?第一次编译这个程序也出现了同样的错误。后来查找,需要两个文件:
http://www.yendor.com/programming/unix/apue/lib.svr4/ourhdr.h
http://www.yendor.com/programming/unix/apue/lib.svr4/error.c

编译的时候用下面参数就可以了:
gcc -Wall -o ls-1 ls-1.c error.c
回复 支持 反对

使用道具 举报

发表于 2009-10-22 20:15:32 | 显示全部楼层
已经2009年了,我找到了这里,谢谢楼上
回复 支持 反对

使用道具 举报

发表于 2009-10-30 13:14:17 | 显示全部楼层

09年了我才出发

您的贴子对于现在的我很受用 谢谢
回复 支持 反对

使用道具 举报

发表于 2009-11-3 20:17:40 | 显示全部楼层
^_^!当年也是这样照猫画虎一知半解地过来的!
回复 支持 反对

使用道具 举报

发表于 2009-11-4 00:28:26 | 显示全部楼层
.        函数未定义
回复 支持 反对

使用道具 举报

发表于 2010-12-6 00:02:19 | 显示全部楼层
好老的帖子,今天又碰到了这个问题了。
回复 支持 反对

使用道具 举报

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

本版积分规则

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