Unix Programming - compile apue

来源:互联网 发布:商务通怎么导出数据 编辑:程序博客网 时间:2024/06/06 09:18

<<Advanced Programming in the Unix Environment>>

$ wget http://www.apuebook.com/src.3e.tar.gz$ make
apue$  cat myls.c#include "apue.h"#include <dirent.h>intmain(int argc, const 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);}
apue$ gcc myls.cUndefined symbols for architecture x86_64:  "_err_quit", referenced from:      _main in myls-dfacfa.o  "_err_sys", referenced from:      _main in myls-dfacfa.old: symbol(s) not found for architecture x86_64clang: error: linker command failed with exit code 1 (use -v to see invocation)

I wanted to know how I can fix this problem. I also want to be able to run a code I write in any directory, can anyone guide me on that too?

apue$  gcc -o myls myls.c -I /Users/helloworld/Desktop/apue.3e/include/ -L /Users/helloworld/Desktop/apue.3e/lib/ -lapue

References

http://unix.stackexchange.com/questions/105483/compiling-code-from-apue
https://segmentfault.com/a/1190000004359057

0 0
原创粉丝点击