First, the source code compilation
1. Source code Download
2, I Linux version Ubuntu 14.04 (gun/linux 3.13.0-0-32-generic x86_64)
3. Prerequisite Preparation
$sudo apt-get Install GCC
$sudo Apt-get Install Libbsd-dev
$CD apue.3e
Make
.. Wait for compilation to complete
Ii. Examples of essays
1, author makefile
Example of the first LS in Chapter one (APUE.3E/INTRO/LS1.C)
First Makefile (Apue.3e/makefile)
1 # The folder to traverse2DIRS =lib intro sockets Advio daemons datafiles db environ3 FileIO filedir ipc1 IPC2 proc Pty relation signals standards4 stdio termios threadctl threads printer Exercises5 # for loop, if you want to traverse with $ $i6 All :7 forIinch$ (DIRS); Do 8(CD $ $i &&Echo "making $ $i"&& $ (make)) | | Exit1; 9 DoneTen One Clean : A forIinch$ (DIRS); Do -(CD $ $i &&Echo "Cleaning $ $i"&& $ (make) clean) | | Exit1; - Done
A second Makefile (Apue.3e/intro/makefile)
1root=..2# Execute apue.3e/systype.SH3platform=$ (Shell $ (ROOT)/systype.SH)4 # Introduction of basic quantities5Include $ (ROOT)/make.defines.$ (PLATFORM)6 # files that need to be compiled7Progs =getcputc Hello ls1 mycat shell1 shell2 testerror uidgid8 9 All : $ (progs)Ten # Execute the GCC command, the corresponding amount of value in the Make.defines.xxx file, @ means the dependent file One%: %. C $ (LIBAPUE) A$ (CC) $ (CFLAGS) [email protected]-o [email protected] $ (ldflags) $ (ldlibs) - - Clean : the RM-F $ (progs) $ (tempfiles) *. O -#引入apue. 3e/Make.libapue.inc File -Include $ (ROOT)/make.libapue.inc
Make.defines.linux (because my platform is Linux)
# Common MakeDefinitions, customized forEach platform# definitions requiredinchAll program directories to compile and link# C programs usingGCC. CC=GCCcompile.c=$ (CC) $ (CFLAGS) $ (cppflags)-clink.c=$ (CC) $ (CFLAGS) $ (cppflags) $ (ldflags) Ldflags=Lddir=-l$ (ROOT)/Libldlibs=$ (Lddir)-Lapue $ (extralibs) #-ANSI ANSI C standard #-I use the following directory as the first directory to look for header files, in order: (ROOT)/include->/usr/include->/usr/local/include#-Wall Show all warning Messages #-D GCC in the macro definition # GCC command-L The directory that is represented later as the first directory to find the library file, in order: (ROOT)/lib->/lib->/usr/lib->/usr/local/Libcflags=-ansi-i$ (ROOT)/include-wall-dlinux-D_gnu_source $ (EXTRA) Ranlib=EchoAR=arAWK=awkLibapue=$ (ROOT)/lib/libapue.a# Common temp files to delete from each directory. Tempfiles=core core.* *.o temp.* *.out
2. Complete the code in the self-built working directory
Copy the codebase to your own directory (MYAPUE)
Building the first chapter code catalog
$mkdir CH1
$CD CH1
Then copy the apue.3e makefile to CH1, remove the values that need to be traversed in the progs to add your own new file
First example: Vim MYLS.C
/ * CommentEssays*///DIR:struct__dirstream {void*__fd; Char*__data; int__entry_data; Char*__ptr; int__entry_ptr; size_t __allocation; size_t __size; __libc_lock_define (, __lock)};typedefstruct__dirstream DIR;//dirent <dirent.h>structdirent{LongD_ino;/*inode Number*/off_t D_off; /*offset to this dirent*/unsigned ShortD_reclen;/*length of this d_name*/ CharD_name [name_max+1];/*file name (null-terminated)*/}
After saving exits, add myls (progs = Myls) in the progs of makefile
$make
./myls/home can list files in the/home directory
<, ..... It's late at night ... To be continued ...>
1, "UNIX environment Advanced Programming" with the mind--basic knowledge