This configuration instance pro-test success, mutual encouragement, there are questions to everyone message.
Environment: VMware + unbuntu 14.04
For UNIX network programming, programming the first UNIX program encountered problems, can not contain unp.h file, this feeling and apue.h almost, but here need to compile source code, for later convenience, now tidy up as follows:
The main 2.1 is to generate LIBUNP.A this library, the second is to get unp.h, config.h these two head files.
1, install the compiler, in order to complete or install a build-essential
- sudo apt-get install build-essential
2, download the book's header file and sample source code
Unpv12e.tar.gz (This compilation has a problem) unpv13e.tar.gz not, can Google a bit.
(If you use unpv13e, you can skip the problem solving in 3)
3, after decompression unpv12e.tar.gz into the directory to see the Readme, and then follow the instructions inside, but you will encounter problems
First step: Enter the upnv12e directory in the terminal and execute the code:
- ./configure
Step two: Here are the problems and solutions
- cd Lib
2.make//This step is wrong.
The error code is:
- Gcc-g-o2-d_reentrant-wall-c-o connect_nonb.o connect_nonb.c
- In file included from CONNECT_NONB.C:1:
- Unp.h:114:error:redefinition of ' struct In_pktinfo '
- Make: * * [CONNECT_NONB.O] Error 1
redefinition of ' struct in_pktinfo ' solution is as follows:
The structure In_pktinfo is already included in the standard header file Bits/in.h, which is also included in the Unp.h by Netinet/in.h. Just comment out the structure definition comment out in unp.h.
Comment out and then re-
- Make//build the basic library, the All programs need
It's a success this time! Generated A: /libunp.a file.
Step three: No problem with this step
- Cd.. /libfree # Continue building the basic library
- Make
Fourth step: This step is a bit of a problem
- Cd.. /libgai # The getaddrinfo () and Getnameinfo () functions
- Make
The error prompts are as follows:
- Gcc-g-o2-d_reentrant-wall-c-o getaddrinfo.o getaddrinfo.c
- getaddrinfo.c:in function ' getaddrinfo ':
- GETADDRINFO.C:58:error: ' eai_addrfamily ' undeclared (first use of this function)
- GETADDRINFO.C:58:error: (each undeclared identifier are reported only once
- GETADDRINFO.C:58:error: For each function it appears in .)
- GETADDRINFO.C:116:error: ' Eai_nodata ' undeclared (first use of this function)
- Make: * * [GETADDRINFO.O] Error 1
Here's how to fix it:
Back to unpv12e directory:
- Cd..
- Gedit Configure. inch
find the following line to comment out
libgai_objs= "getaddrinfo.o getnameinfo.o freeaddrinfo.o gai_strerror.o"
and use the following code instead of the commented out line.
- libgai_objs=
- if test "$ac _cv_func_getaddrinfo" = no; Then
- libgai_objs= "$LIBGAI _objs getaddrinfo.o"
- Fi
- if test "$ac _cv_func_getnameinfo" = no; Then
- libgai_objs= "$LIBGAI _objs getnameinfo.o"
- Fi
- if test "$ac _cv_func_freeaddrinfo" = no; Then
- libgai_objs= "$LIBGAI _objs freeaddrinfo.o"
- Fi
- if test "$ac _cv_func_gai_strerror" = no; Then
- libgai_objs= "$LIBGAI _objs gai_strerror.o"
- Fi
- Autoconf
- ./configure
- Gedit Make.defines
Add the following sentence at the end of the document:
CFLAGS =-g-o2-d_reentrant-wall
-d_gnu_source
Then re-execute the code:
- CD Libgai # Continue building the basic library
- Make
OK, the problem is solved!
4, copy the generated libunp.a static library to/usr/lib/and/usr/lib64/.
- Cd.. Back to unpv12e Directory
- sudo cp libunp.a/usr/lib
- sudo cp libunp.a/usr/lib64
5, modify unp.h and copy it and Config.h to/usr/include, for later include convenient
- Gedit lib/unp.h//Will be unp.h in #include ". /config.h "modified to include" Config.h "
- sudo cp lib/unp.h/usr/include
- sudo cp config.h/usr/include
6, compiling the source code
- CD Your program directory
- GCC Daytimetcpcli.c-o DAYTIMETCPCLI-LUNP
Unlike the normal compilation is to add just that the link library, the-l parameter plus just that Libunp.a removed Lib and the back. Finally get the parameter-LUNP.
7, write the program
The code compiled in the later program installation 6 will work, and then the code will be exactly the same as in the book. The code Editor or IDE is chosen to your liking. This online many C language programming environment Construction tutorial.
I choose the command line with vim to write programs, mainly to exercise themselves.
Now learn from the Internet, their own test success, then there are problems, I will continue to fill up, share with you.
UNIX NetWork Programming (UNIX Environment Programming)-Environment building (solving unp.h and other source code compilation problems)