First make sure that GCC is already installed in the operating system.
Unzip the apue.2e into the Linux operating system and enter
[[Email protected] apue.2e]# CD Lib
Enter the Lib folder of the apue.2e.
[Email protected] lib]# make-f linux.mk
Then find libapue.a from the Apue.2e/lib folder, find apue.h from the Apue.2e/include folder, and copy both to the source directory (the directory where you wrote your. c file), enter
[Email protected] test]# Gcc-o main MAIN.C libapue.a
Compilation succeeded, input
[Email protected] test]#./main/dev
can be run.
Appendix:
Run the program code as follows:
#include"apue.h"#include<dirent.h>intMainintargcChar*argv[]) {DIR*DP; structDirent *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);}
The purpose of this program is to print the names of each file in a directory.
UNIX Environment Advanced Programming CentOS Configuration APUE compilation environment