Free Windows C Compilers

© Copyright 2003 by Peter C. Chapin
Last Revised: July 2003


Introduction

Many students in VTC's C and C++ programming classes ask about how they can get a compiler to use on their own system. Although the compilers used by VTC can't (normally) be installed on student machines, there are a number of free options available to students. It is the purpose of this document to describe those options. Note that this document assumes you are using a Windows system. If you have a personal Linux system, you certainly have access to the GCC compiler. This document does not discuss options for Apple systems

The compilers are listed below in order of increasing "heaviness". The first compiler on the list is relatively small and simple. The later compilers are larger and, typically more complicated to install and use. All of these compilers can be downloaded and installed for no charge.

  1. LCC-Win32
  2. OpenWatcom
  3. Cygwin/GCC

LCC-Win32

Section Last Revised: 2003-07-23

Legal Status

LCC-Win32 is free for personal, non-commercial use. If you sell the software you produce with LCC-Win32 or use it in a corporation (including a classroom) you must buy a license. However, the author has informed me in email that "personal use" includes students using it on their own machines... even if such usage is to do programming assignments. See the LCC-Win32 web site (URL below) for more information.

The author of LCC-Win32 suggested to me that students consider buying the CD-ROM distribution of the system. In addition to sparing you the trouble of downloading all the files, the CD-ROM distribution comes with numerous examples that might be of interest. It also helps to support the LCC-Win32 development effort.

Downloading and Installing

The main LCC-Win32 site is http://www.cs.virginia.edu/~lcc-win32/. Go there to download the latest version of the system. LCC-Win32 is updated frequently.

There are several files you can download but not all of them are necessary.

  1. lccwin32.exe. This is the base system. It is required.

  2. manual.exe. This is the documentation for the compiler product and its tools. You should download this as well.

  3. tutorial.pdf. This is an extensive C tutorial. It covers the basics of C as well as a number of advanced topics. It also discusses how to use LCC-Win32 to develop graphical Windows applications. You might consider downloading this document to use as a supplement to your text book or class notes.

  4. win32hlp.exe. This is the Windows API documentation. It is only necessary if you plan on developing graphical Windows applications and don't have access to API documentation from any other source. You do not need this file for writing standard, ANSI C programs.

  5. lccdoc.exe. This is technical documentation on the internal design of the LCC-Win32 compiler and tools. It is not necessary for writing programs. The documents in this file are all in Microsoft Word format. This file also contains the documentation in manual.exe (in Word format).

Each of the files I mentioned above (except for the PDF file) are InstallShield executables. Just double click on the file to install it. You will be asked where to install the product. The usual location is c:\lcc. Whatever location you choose you should probably be consistent and use the same location for each component. If you want to use the command line tools, you will need to manually add the LCC bin directory to the path. Exactly how to do that depends on your operating environment.

WinNT (Win2k/WinXP ??)

Open the control panel and double click on the "System" icon. Click on the environment tab and then select "Path" in the "User Variable" section that appears. If you are logged in as Administrator and want the change to occur for ever user, you can modify the path in the "System Variable" section. Add c:\lcc\bin to the end of the list of folders presented there (use a semicolon between folder names), click "Set", and then close the system property sheet. Open a fresh command prompt to get an environment containing the change. It should not be necessary to reboot the system.

To access the documentation you may want to manually create a shortcut to the lcc.chm file (probably in the c:\lcc\doc folder). You may also want to manually create shortcuts to the c-library.chm file (probably in c:\lcc\bin) and the strlib.chm file (also probably in c:\lcc\bin). Note that most of this documentation is accessible from the help menu of the IDE should you choose to do your development using the IDE (see below).

Compiling Programs

To compile short, simple programs you will probably find the command line tools to be the easiest to use. Use any text editor (PFE, XEmacs, etc) to create your program. Open a command prompt and use the cd command to change to the folder containing your program. The commands below assume that the program is named hello.c

C:\home\peter> lcc hello.c
C:\home\peter> lcclnk hello.obj

Notice that you must use two commands to create your executable file. To run the program just type its name

C:\home\peter> hello

I suggest that you write a program that uses printf to print "Hello, World" on the console and then use the commands above to compile and run it. That will give you confidence that you have installed LCC-Win32 properly.

Using the Integrated Development Environment

If you are building a large program (especially one consisting of many source files) you might want to use the IDE instead of the command line tools. You might also find the IDE more interesting and more fun to use. However, the IDE is also a lot more complicated. If you find the IDE confusing and difficult, stay away from it. The command line tools are sufficient to get the job done.

If you do want to use the IDE, you need to be aware of several points.

  1. The IDE organizes your programs in terms of projects. Each project can consist of many source files along with various compiler options that are set uniquely for that project. Each project generates a single executable file.

  2. In addition to your source files, the IDE will create some control files pertaining to your project. This is normal so don't be alarmed to discover several "strange" files along with your program files.

  3. Each project must reside in its own folder. You can't put two projects in the same folder due to name conflicts on certain control files.

Suppose you want to use the IDE to build the "Hello, World" program. Follow these steps.

  1. Start the IDE. It is called Wedit. A shortcut to it should have been added to your start menu when you installed LCC-Win32.

  2. Pull down the project menu and select "Create...". In the dialog box that appears, enter a name for your project. For example, you might enter "hello". Be sure to enter the project's working directory (folder). Wedit will create it if it doesn't exist. Most likely you'll want to use a folder that doesn't exist when you create a new project. The output directory (folder)is where the output files will go, such as the executable file. I suggest making that the same as the project's working directory. Verify the other settings in this dialog box... particularly the "Type of project" setting. For simple programs you want "Console Application".

  3. When you press "Create" you will be asked if you want to use a wizard to generate the application's skeleton. Say "no".

  4. Next you will be asked to select source files for the project. You can type the name of a file that does not exist (yet) at this point.

  5. After you have added all the source files you care about (for a simple program there will be only one), press the "OK" button. You will then be presented with several dialog boxes of compiler settings. For simple programs, all the defaults are acceptable. You might review the settings anyway just as a matter of interest. You can change them later if you wish. You might want to select "Warning level: All" if you are just learning C. Compiler warnings can often help you find bugs.

  6. When you press "Finished" the IDE creates a special control file in your project's working directory named "Makefile". This file defines how the various files composing your project are compiled and linked. Do not delete it!

  7. You are now ready to edit your source file(s) using the integrated editor. When you want to create the executable, press the F9 key or select "Make" from the "Compiler" menu.

Note that when you exit Wedit, it remembers which project was open and it will automatically reopen that project when you next start Wedit. That is sometimes useful, sometimes annoying. When you are done working with a project, you should probably explicitly close it by selecting "Close..." from the "Project" menu.

It may sound like using the IDE is a big hassle, but actually once you get used to it the process is pretty straightforward. You may find that you soon like the IDE and want to use it all the time.


Open Watcom

Section not yet written


Cygwin/GCC

Section not yet written


© Copyright 2003 by Peter C. Chapin.
Last Revised: July 26, 2003