Advanced programming in Unix environment - solve the first problem "apue.h: No such file or directory"

-------------------------------------------------- "Advanced Programming in Unix Environment" notes details (1) --------------------------------------- -------------------------                                       

The first time I came into contact with "Advanced Programming in the Unix Environment" (Third Edition) was in my junior year. I was in a fog, and soon I went from getting started to giving up. After finishing the embedded course in my senior year, I watched some videos on station b, and then read this book, only to realize how powerful this book is. Many videos and tutorials are based on this book to introduce Linux (Linux is a Unix-like operating system, Unix is ​​earlier than Linux, the original intention of Linux is to replace UNIX, and optimize the function and user experience, so Linux It imitates UNIX (but does not copy the source code of UNIX), making Linux very similar to UNIX in appearance and interaction. If you want to know the story between Unix and Linux, you can look at the website I searched casually: http:// c .biancheng.net/view/707.html ,)

Work is nothing more than a process of problems and problem solving, so, today, start the journey of "Uinx Environment Advanced Programming" with a problem and how to solve it.

Problem - When compiling the source code of the book, the following error occurs: "apue.h: No such file or directory"

Why does this problem arise? You have read my notes before: https://mp.csdn.net/console/editor/html/88817936 , you can find that as long as there is an API call, you need to have a corresponding header file. We use the man manual to view the function It can also be clearly seen when prototyping. When the number of APIs is larger, the more header files are required, so the header files look very long without looking at the code. Therefore, in order to greatly reduce the length of the sample code, the author of "Advanced Programming in Unix Environment" encapsulated a lot of code including header files into the apue.h file (see Appendix B of the book for details)

Solve the problem:

1. Download the source code

Download all source codes from the official website of unix advanced programming books: http://www.apuebook.com . Of course, if you don’t want to use a browser, you can also use the command:

wget http://www.apuebook.com/src.tar.gz

Select the corresponding version and download the source code

2. Unzip this file

tar -zxvf src.tar.gz

After decompression, the files will be placed in the apue.2e directory, which contains the source code in the book, and also contains the apue.h and error.c files.

3. Copy apue.h to /usr/include/

cp ./apue.2e/include/apue.h /usr/include/

At this time, there is no apue.h file under /usr/include/ , just copy it directly

4. Copy error.c to /usr/include/

cp ./apue.2e/lib/error.c /usr/include/

 Pay attention to see error.c here, step three is errer.h

Five, /usr/include/apue.h file configuration

Open the file with vi editor:

vi /usr/include/apue.h

Add the code containing error.c before #endif at the end of the file:

#include "error.c";

Done!

Next, you can easily compile the source code of the book and start your journey of "Advanced Programming in Unix Environment"! ! come on! Ori! ! !

 

 

------------------------------------------------ If you think this article is okay If so, like and collect, make friends ----------------------------------------- -------------------

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/qq_41899773/article/details/107376991