<<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>
int
main(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.c
Undefined symbols for architecture x86_64:
"_err_quit", referenced from:
_main in myls-dfacfa.o
"_err_sys", referenced from:
_main in myls-dfacfa.o
ld: symbol(s) not found for architecture x86_64
clang: 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