Just now I have began reading the book: Advanced Programming in the UNIX® Environment. I wanted to try running its first code example. I am running Scientific Linux 6.4.
I downloaded the source code and as it says in its README, I ran make
in the uncompressed file.
I wrote the first program (a mock ls
command)
#include "./include/apue.h"
#include <dirent.h>
int
main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if(argc!=2)
err_quit("usage: test 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);
return 0;
}
and put it in the uncompressed file. As the book had advised I then ran: gcc myls.c
. But I get this error:
# gcc myls.c
/tmp/ccWTWS2I.o: In function `main':
test.c:(.text+0x20): undefined reference to `err_quit'
test.c:(.text+0x5b): undefined reference to `err_sys'
collect2: ld returned 1 exit status
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.
err_{quit,sys}
to come from? – Chris Down Dec 17 '13 at 03:24include
, that has the header fileapue.h
. But this is the only file in that directory. I don't understand where the actual function definitions are! I thought someone may be familiar with the source code file structure of this book here. – makhlaghi Dec 17 '13 at 03:28.h
files include the protypes for the functions. Their implementations are in.so
or.a
files which need to be present on the box. These are dynamic & static libraries which contain the functions. – slm Dec 17 '13 at 03:49apue.h
? – voices Mar 17 '19 at 15:33