Lawrence Technological University
College of Arts and Science
Department of Mathematics and Computer Sciences

Handouts

Cygwin setup for an LTU Laptop

Why Cygwin? The laptop is a convenient tool on which to learn the C language. The command line is the focus of most textbooks on C, including the text for MCS 1142. Unfortunately, most laptops run Windows and the Command Prompt window in Windows is not a very good programmer's tool. C++Builder and Visual Studio C++ are the two Windows C++ tool-sets often found at LTU. Both are large programs that are made to ease the job of writing and revising large multi-part programs. For Introduction to Programming in C, we will be working on C on the command line, except for a one-week digression to windowing and Web programming. The original authors of C, advised that C is a small language and it is not well served by a large book. Similarly, learning to write small, straightforward, C programs is made unnecessarily difficult by using an Integrated Development Environment like Builder or Visual Studio that is optimized for large projects.

The default Base Cygwin package gives you the BASH shell to use instead of the DOS emulation shell in the Windows Command Prompt "black window." Just the command history that remembers from session to session and the command completion features will save you a lot of typing in the course of a semester.

The main reason, however, to set up Cygwin for MCS 1142 is that Cygwin is the easiest way to get and use the gcc C compiler. You can also use bcc32 from Builder or cl from Visual Studio at the Command Prompt. gcc is the only one of the three that will allow you to try your C on other platforms... perhaps a PowerBook or a 68HC11 development board.

To get started in command line C

  1. Create a folder for your class work under your own home folder. On my machine that was c:\Documents and Settings\jmmiller\mcs1142
  2. You can use Notepad. Taking the time to install a real programmer's editor with a spell-checker, Emacs would be a good idea at this point.
  3. Setup.exe running Go to www.cygwin.com and simply click on any of the Install Cygwin now links. If you select "Open" IE will save Setup.exe to a temporary folder and run it... bringing up this screen. In general, just accept the defaults. Some options
  4. Now add ;c:\cygwin\bin;c:\Documents and Settings\your-id\mcs1142 to the the end of your Path Environment variable (found by right-clicking on My Computer and selecting the Advanced tab.) This will help Windows find the cygwin1.dll if you run your newly compiled C program from the ordinary command Prompt. The second part also helps Cygwin find your freshly compiled C programs.
  5. Now open Emacs (or NotePad if you must) and copy
    /* hello.c
       a test program
    */
    #include <stdio.h>
    main()
    {
      printf("Hello, World\n");
      return 0;
    }
    
    to c:\Documents and Settings\your-id\mcs1142\hello.c
  6. Click your Cygwin icon and
    JMMILLER@LTUN0203 ~
    $ cd mcs1142
    
    JMMILLER@LTUN0203 ~/mcs1142
    $ ls
    hello.c
    
    JMMILLER@LTUN0203 ~/mcs1142
    $ gcc hello.c -o hello.exe
    
    JMMILLER@LTUN0203 ~/mcs1142
    $ ls
    hello.c  hello.exe
    
    JMMILLER@LTUN0203 ~/mcs1142
    $ hello
    Hello, World
    
    JMMILLER@LTUN0203 ~/mcs1142
    $logout
    

Revised August 25, 2004