Compiling Network Programs

This page contains some "hints" for compiling network programming under Unix and MS Windows.

Compiling network programs on Unix

You should have linked programs on a Unix computer, such as bulldog, in CSCI 202. However, just in case you've forgotten, I'll give you an example command for compiling and linking a C program.

This example assumes that the program source is stored in netprog.c and that the executable should be stored in netprog.

You will need to use library functions of the socket API, such as connect and gethostbyname, in this class. Before using a routines for the first time, you should look its man page, but typing a command similar to:

The man pages will give you three important pieces of information.

  1. You'll see the routine prototype: This will tell your the arguments and return value of the routine.
  2. You'll see the include files that are needed by the routine. The man page will include C-style include statements, such as that should be placed near the beginning of your program.
  3. You may see references to libraries that should be linked in with your program. On Solaris computers this information is given as the first line of the SYNOPSIS section which looks something like: The compiler options starting with -l must be used when compiling your program to include the necessary libraries. In general, you will need to include the libraries -lsocket and -lnsl when compiling socket programs.

    On Compaq Tru64 Unix (formerly know as Digital Unix) computers this information will be given in the LIBRARY section:

    However, since Compaq Tru64 Unix generally places all the socket API functions in the stanard library, you don't have to worry about including any special libraries when you compile your code.

If you are compiling programs on a Unix computer, you really ought to be using Make. If you don't know how to use Make, you should get a good Unix reference. Example Makefiles for both Solaris and Compaq Tru64 Unix can be found with the following links:

Compiling network programs under Visual C++

The Visual C++ development environment is not an easy one to master. Hopefully, you have already compiled programs using Visual C++ in CSCI 201. If you haven't, you really need to check out some of the early CSCI 201 labs.

In order to run Windows programs that use the Winsock interface, you must include a Winsock library into your project. I included the library stored in C:\Program Files\Microsoft Visual Studio\VC98\Lib\Wsock32.lib when I compiled my Winsock applications. I suspect the smarter approach would be to include one of the Winsock dynamic link libraries (dll's), but I never mastered that trick. If you do figure out how to use the Winsock dll, please tell me the secret.

Back to the CSCI 363 homework page
Back to the CSCI 363 home page