unix环境高级编程第一个例子ls.c:
05 | main( int argc, char *argv[]) |
11 | err_quit( "usage: ls directory_name" ); |
13 | if ((dp = opendir(argv[1])) == NULL) |
14 | err_sys( "can't open %s" , argv[1]); |
15 | while ((dirp = readdir(dp))!=NULL) |
16 | printf ( "%s\n" ,dirp->d_name); |
编译出错:
[john@localhost apue]$ gcc ls.c
/tmp/cchIn3xL.o: In function `main':
ls.c:(.text+0x17): undefined reference to `err_quit'
ls.c:(.text+0x4a): undefined reference to `err_sys'
发现是找不到err_quit和err_sys,于是把unix环境高级编程源码的lib目录下的error.c拷贝出来和一起编译:
[john
@localhost apue]$ gcc ls.c error.c
OK,解决了。