unix环境高级编程第一个例子ls.c: shell
#include "apue.h" #include <dirent.h> int main(int argc,char *argv[]) { DIR *dp; struct dirent *dirp; if(argc != 2) err_quit("usage: ls directory_name"); 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); }
编译出错:
编程
[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拷贝出来和一块儿编译:
ui
[john@localhost apue]$ gcc ls.c error.cOK,解决了。