(a) First to compile all the source code
1. APUE2 Source Download: http://www.apuebook.com/src.tar.gz
2. Unzip under directory/work/apue: TAR–XZVF src.tar.gz
3. CD apue.2e into the apue.2e directory, cat README, see instructions. Modify the Make.defines.linux file according to the system used to modify the appropriate files, such as the Linux system. Edit the content of the file is mainly to modify the Wkdir, that is, the source of the folder's absolute path name. The original file in wkdir=/users/sar/apue.2e, I modified to/users/kirchhoff/apue.2e. Save the changes.
4. If you do not know your system type, there is a systype.sh script in the current directory that can detect the type of operating system: Freebsd,linux,macos, Solaris, and so on. Execute this script:
./systype.sh
If you do not have Execute permissions, execute the
#chmod u+x systype.sh
Add executable permissions to the current user.
In fact, the simplest way is to execute directly
Uname–s
command to see what system is currently in use.
5. Source code compilation. Execute command:
Make
In the makefile file, after make, the systype.sh script is executed first, that is, the type of the operating system is first determined, and then the source code is compiled. Some warning may occur during compilation, which are normal, and may be caused by different versions of the compiler or different versions of the same type of operating system. However, as long as the make process does not appear error, it will succeed in compiling successfully.
At this point, the source code compilation is over, but where is the executable that we compiled the build from? Under the apue.2e directory, the figx.x name is a link. But the actual compilation process is not compiled by these files. Instead, the program is compiled in various folders with the suffix named *.c. The author places the source code under one folder (except for the Include and Lib folders) in the same section or several chapters. and the name of the folder is generally consistent with the title of the chapter, the use of the English title is the full name or shorthand. For example, the Advio folder corresponds to Chapter 14. Advanced I/O, the code for this chapter is placed below the folder. There are also folder proc corresponding to Chapter 8. Process Control, Folder Termios corresponds to Chapter 18. Terminal I/O and so on, basically each chapter of the code can be found in these folders.
(ii) compiling a single source file:
Apue programming examples are related to include "Apue.h" code, in fact, apue.h is not the system comes with, it is the author of the header file, the source code in Appendix B. So one way is to. Copy the/apue.2e/include/apue.h you just generated directly to Under the/usr/include.
Cp/users/kirchhoff/apue.2e/include/apue.h/usr/include
There are error handlers, like Err_quit and Err_sys, that are defined by the author themselves, and need to define the header file separately
Create a new file named Myerr.h under/usr/include, and copy the contents of "Figure B-2 output to the error handler of the standard error file" to Myerr.h. If you don't want to hit the code yourself, you can use the file provided in the source code directly, using the following command:
Cp/users/kirchhoff/apue.2e/lib/error.c/usr/include/myerr.h
Then, when writing the program, this includes the header file:
#include "apue.h"
#include "Myerr.h"