UNIX NetWork Programming (UNIX Environment Programming)-Environment building (solving unp.h and other source code compilation problems)

Source: Internet
Author: User

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

    1. 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:

    1. ./configure

Step two: Here are the problems and solutions

    1. cd Lib

2.make//This step is wrong.

The error code is:

    1. Gcc-g-o2-d_reentrant-wall-c-o connect_nonb.o connect_nonb.c
    2. In file included from CONNECT_NONB.C:1:
    3. Unp.h:114:error:redefinition of ' struct In_pktinfo '
    4. 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-

    1. 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

    1. Cd.. /libfree # Continue building the basic library
    2. Make
Fourth step: This step is a bit of a problem
    1. Cd.. /libgai # The getaddrinfo () and Getnameinfo () functions
    2. Make
The error prompts are as follows:
  1. Gcc-g-o2-d_reentrant-wall-c-o getaddrinfo.o getaddrinfo.c
  2. getaddrinfo.c:in function ' getaddrinfo ':
  3. GETADDRINFO.C:58:error: ' eai_addrfamily ' undeclared (first use of this function)
  4. GETADDRINFO.C:58:error: (each undeclared identifier are reported only once
  5. GETADDRINFO.C:58:error: For each function it appears in .)
  6. GETADDRINFO.C:116:error: ' Eai_nodata ' undeclared (first use of this function)
  7. Make: * * [GETADDRINFO.O] Error 1

Here's how to fix it:

Back to unpv12e directory:

    1. Cd..
    2. 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.
    1. libgai_objs=
    2. if test "$ac _cv_func_getaddrinfo" = no; Then
    3. libgai_objs= "$LIBGAI _objs getaddrinfo.o"
    4. Fi
    5. if test "$ac _cv_func_getnameinfo" = no; Then
    6. libgai_objs= "$LIBGAI _objs getnameinfo.o"
    7. Fi
    8. if test "$ac _cv_func_freeaddrinfo" = no; Then
    9. libgai_objs= "$LIBGAI _objs freeaddrinfo.o"
    10. Fi
    11. if test "$ac _cv_func_gai_strerror" = no; Then
    12. libgai_objs= "$LIBGAI _objs gai_strerror.o"
    13. Fi
    1. Autoconf
    2. ./configure
    1. 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:

    1. CD Libgai # Continue building the basic library
    2. Make

OK, the problem is solved!

4, copy the generated libunp.a static library to/usr/lib/and/usr/lib64/.

    1. Cd.. Back to unpv12e Directory
    1. sudo cp libunp.a/usr/lib
    2. sudo cp libunp.a/usr/lib64

5, modify unp.h and copy it and Config.h to/usr/include, for later include convenient

    1. Gedit lib/unp.h//Will be unp.h in #include ". /config.h "modified to include" Config.h "
    1. sudo cp lib/unp.h/usr/include
    2. sudo cp config.h/usr/include

6, compiling the source code

    1. CD Your program directory
    2. 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.