Environment:
Ubuntu10.04
G ++/GCC 4.4.3
Note:
Some websites repost myArticleIf the source is not indicated and the reposted information is not in place, the corresponding link is not transferred, for example, the download link or the link to the relevant document, as a result, some netizens may encounter reading and usage obstacles and the knowledge is not continuous. Therefore, I am particularly noted that my article is published on the csdn-jasonque blog and can be read by csdn blogs.
Body:
Start to chew on UNIX Network Programming: Volume 1.
After reading the first chapter, download the source code of the book and start running it.ProgramThis is a big blow, either less or less. I can see a lot of files and folders in the source code folder. I don't know where to start. The source code file in the first chapter is in the "Intro" folder. I directly enter the "make" command on the terminal, it is an error. Miserable. Looking for information online, it seems that "experts" are reluctant to discuss such idiotic questions in detail. Helpless, please rely on yourself.
Come back and look at the source code folder and find that there is a "readme" file, which has never been used to reading this file before, because there are a lot of readme files, there are all advertisements or a large piece of seemingly unrelated content. But here it is not. You must take a careful look. You can save your life !!!!
------ Readme --------
quick and dirty ==================== execute the following from the src/directory: . /configure # Try to figure out all implementation differences CD lib # build the basic library that all programs need make # Use "gmake" everywhere on BSD/OS systems CD .. /libfree # continue building the basic library make Cd .. /libroute # Only if your system supports 4.4bsd style routing sockets make # Only if your system supports 4.4bsd style routing sockets CD .. /libxti # Only if your system supports xTi make # Only if your system supports xTi Cd .. /intro # build and test a basic client program make daytimetcpcli. /daytimetcpcli 127.0.0.1 if all that works, you're all set to start compiling individual programs. notice that all the source code assumes tabs every 4 columns, not 8.
The above is very clear. In the terminal, go to the source code folder and run the following command:
#./Configure
If the permission is insufficient, modify the File Permission as follows (I am relatively lazy and open all the files to the masses)
Then run"./Congfigure"Command, as shown in the setting process:
Go to the "lib" folder and run the "make" command:
Go to the "libfree" folder and run the "make" command:
In this way, everything is ready (there are several other commands for other system environments, so I won't talk about them here ).
In this case, you can directly go to the "Intro" folder and directly run the "make" command to get the final running file.
But here I want to talk about it. All the way down, I found that "readme" is a silly one, as long as there is make, then I am simply a "animal" that will only take my sister and will not think about.
Since we only use two programs on the client and server, that is, two. C source code files, why should I compile all. c files? So how can we control the compilation of only these two files? Of course, it is possible to directly use the GCC command to Compile two source code files, but the relevant library connection in the file must be modified. In addition, if you want to write a program, especially a large program, you 'd better have a deep understanding of the MAKEFILE file. Of course, you can't eat it as a fat man, so let's just take a bite.
During this period, I read the makefile series of articles "write makefile With Me" by Chen haobo in csdn, Which is concise and easy to understand. Later, let's look back at the source code file. In fact, after the preliminary work, I made the sister (make) constantly. The relevant library is ready, and each category folder also contains a MAKEFILE file, open makefile in the intro folder, which is quite simple.CodeComment out and leave the ones you are interested in, as shown below:
-------------- Intro/makefile ------------------------
Include .. /make. definesprogs = commandid # daytimetcpsrv daytimetcpsrv1 daytimetcpsrv2 daytimetcpsrv3 \ # commandid \ # byteorderall :$ {progs} daytimetcpcli: daytimetcpcli. o $ {CC }$ {cflags}-o $ @ daytimetcpcli. o $ {libs} # daytimetcpcli1: daytimetcpcli1.o #$ {CC }$ {cflags}-o $ @ daytimetcpcli1.o $ {libs} # daytimetcpcli2: daytimetcpcli2.o #$ {CC }$ {cflags}-o $ @ daytimetcpcli2.o $ {libs} # daytimetcpcli3: daytimetcpcli3.o #$ {CC }$ {cflags}-o $ @ daytimetcpcli3.o $ {libs} daytimetcpsrv: daytimetcpsrv. o $ {CC }$ {cflags}-o $ @ daytimetcpsrv. o $ {libs} # daytimetcpsrv1: daytimetcpsrv1.o #$ {CC }$ {cflags}-o $ @ daytimetcpsrv1.o $ {libs} # daytimetcpsrv2: daytimetcpsrv2.o #$ {CC }$ {cflags}-o $ @ daytimetcpsrv2.o $ {libs} # daytimetcpsrv3: daytimetcpsrv3.o #$ {CC }$ {cflags}-o $ @ daytimetcpsrv3.o $ {libs} # daytimetcpcliv6: daytimetcpcliv6.o #$ {CC }$ {cflags}-o $ @ daytimetcpcliv6.o $ {libs} # daytimetcpsrvv6: daytimetcpsrvv6.o #$ {CC }$ {cflags}-o $ @ daytimetcpsrvv6.o $ {libs} # byteorder: byteorder. O # $ {CC }$ {cflags}-o $ @ byteorder. o $ {libs} clean: Rm-F $ {progs }$ {cleanfiles}
After saving the MAKEFILE file, run the make command on the terminal to compile the client and server running files that you need.
As for the makefile architecture of the entire large source code file, do not rush to analyze it. At least the modifications made here are sufficient and valuable. Follow the book, analyze the entire MAKEFILE file architecture after analyzing the source code one by one, then the idea will be clearer and the gains will be greater.
The source code file and its analysis are not listed here, and the book is very clear. Run the program directly to see how it works.
First, run the server, as shown in the following figure. After running, the server is in a blocking wait state. (The program contains an endless loop. to exit the program, you can only press Ctrl + c ):
Then run the client to obtain the server system time, as shown below:
OK. The first program example ends here!