Stevens's UNIX Network programming Volume 1: Socket Networking API is a well-known UNIX network programming book. The use of a unp.h reference, if not set up the corresponding library, even if the introduction of the header file is useless. So first you have to configure the appropriate library.
Basic Environment:
Operating system Debian
Development environment Gcc,make, and so on, first of all have C compiler, make and other basic tools. If not, you can install it by following the command. This command installs a toolset that contains many of the tools needed for Linux C development.
sudo apt-get install build-essential
(1) Download unpv.13e.tar.gz from the Internet. A lot of searches on the internet. unpv.12e.tar.gz version of the problem, so to avoid using. Download the installation package after decompression can follow his Readme file instructions installed. The extracted command is
TAR-XVF unpv.13e.tar.gz
(2) You can now CD to the unpv13e directory. Execute the following two commands to generate the corresponding library functions in the unpv13e directory.
CD unpv13e
./configure
cd Lib && make
(3) Return the unpv13e directory and copy the generated libunp.a to the appropriate library file directory. The corresponding shell command.
CD..
sudo cp libunp.a/usr/lib
sudo cp libunp.a/usr/lib64
(4) Modify unp.h and copy it and config.h to/usr/iinclude
Gedit lib/unp.h //Will be unp.h in #include ". /config.h "modified to #include" config.h "
sudo cp lib/unp.h/usr/include
(5) Write a small program to test it, in the unpv13e intro directory contains a few examples. Can be used to test. See if you can generate the appropriate executable file.
CD./intro
Appendix: Libraries in Linux
Libraries exist as a form of software, which is designed to improve the reusability of software. The library encapsulates data and functions. The library can be divided into two kinds: static library and dynamic library. In a Linux system, a library file is usually placed in a/usr/lib or/lib directory. The Linux library file name consists of prefix Lib, library name, and suffix, where the dynamic library suffix is. So, and the static library suffix is. A.
When you use static libraries and dynamic libraries in your programs, they are loaded in a different order. The code for the static library is copied to the application when it is compiled, so when multiple applications refer to a static library function at the same time, memory has multiple copies of the calling function. , the advantage is that it can save time for compiling. Dynamic libraries are loaded only if the library function is called after the program starts to run, and only one copy of the called function is in memory, and the dynamic library can release the memory of the dynamic library while the program is running.
(1) Creation and use of static libraries
The steps to create a static library are as follows:
1 Declare a function exported by the static library in a header file.
2 Implement the function exported by the static library function in a source file.
3 Compile the source file and generate executable code.
4 Add the target file where the executable code is located to a static library, and copy the static library to the system default repository file directory.
Compiling and adding a static library
Gcc-o mylib.o-c mylib.c
ar RCS LIBMYLIB.A MYLIB.O
The AR command can create and modify static libraries. Specific see: Man AR
(2) Creation and use of dynamic libraries
The above configuration process creates a dynamic library. In compiling functions that contain dynamic libraries, you can use the option "-LUNP" (which contains the library files compiled above). The program calls the functions in the dynamic-link library libunp.so. In-LUNP,-l is the option, UNP is the library name. UNP is the middle part of "libunp.so", so the library in Linux starts with Lib, without the prefix and suffix when compiling the program.
Compiling and adding dynamic libraries
Gcc-fpic-o mylib.o-c mylib.c
gcc-shared-o libmylib.so mylib.o
Or
Gcc-fpic-shared-o libmylib.so MYLIB.C
Reference: UNIX network environment collocation
UNIX Network Programming Tour-Configure the Unp.h header file environment [turn]
LInux C Real-combat programming