Lcc-win32 is a freely available (for non-commercial use) C compiler (not C++). This page shows you how to install and use this compiler. Below are several steps that lead you through the installation.
Lcc-win32 is not just a C compiler. It is actually a fairly complete IDE (Integrated Development Environment). If you want to, you can use the lcc-win32 compiler through the IDE. But the following steps show you how to access the lcc-win32 compiler from outside the IDE by using a programmer's text editor called TextPad as a kind of baby IDE. This way of writing and compiling C programs has some real advantages (mainly simplicity) when you are working on small programs.
- Step 1:
- First you need to download three installer files. Put these files in some temporary location on your computer. (If you need to get started in a hurry, you do not really need the 2nd and 3rd files. You can get started with just the first file.)
Lcc-win32 Compiler System
C Standard Library help file
Windows API help file (12.8 MB) (No longer available?)
- Step 1.5 (Optional):
- If you want more documentation, you can also download the following files.
C-Tutorial
Advanced C programming
Lcc-win32 technical documentation (No longer available?)
- Step 2:
- Now run the installers in the order that they are listed above. Have the installers install your copy of lcc-win32 in the directory
C:\lcc . Do not install lcc-win32 in the C:\Program Files directory. The space in that directory name can cause all kinds of problems.
- Step 2.5 (Optional):
- The lcc-win32 installer creates a "lcc-win32" program group in your Start Menu. Look in this program group and start the program called lcc-win32. This starts up the IDE. If you wish, read the documentation that comes with the IDE (if you installed the documentation). Also, here is a very brief tutorial on using the IDE. I will not describe how to use the lcc-win32 IDE. Instead, the remaining steps show you how to use the TextPad editor as a simple IDE.
- Step 3:
- If you have already installed TextPad on your computer (for use with another programming language), then skip to Step 5. Otherwise, download the TextPad text editor (the current version, at the time of this writing, is TextPad Version 4.7.3). TextPad is shareware; you can download and use it for free for a trial period, but then you are supposed to pay a shareware fee if you plan to continue using it. Use the following link to download the installation file (which is just over 2 MB in size).
ftp://download.textpad.com/pub/textpad4.7/txpeng473.exe
- Step 4:
- Install TextPad by double clicking on the installer that you just downloaded.
- Step 5:
- Run TextPad by finding it in your Start Menu. Click on the Tools menu at the top of the TextPad window. Several "tools" are pre-installed by TextPad. We need to install five new tools that let us use lcc-win32 from within TextPad.
- Step 6:
- We need to create a tool in TextPad to call the lcc-win32 compiler. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory
C:\lcc\bin and then in that directory double click on the program lcc.exe . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "lcc". Click on the item "lcc". This brings up a window where we can configure the "lcc" tool. In the text box labeled "Parameters:" enter the following text. (Note: Upper and lower case matter! The best way to enter the text is to use cut and paste from here to the text box.)
-S -c -g2 $File
In the text box labeled "Initial folder:" enter the following text:
$FileDir
Make sure that the check boxes labeled "Save all documents first" and "Capture output" are checked. In the text box labeled "Regular expression to match output:" (below all of the check boxes) enter the following text in place of what is currently there:
^\(Error\|Warning\) \([^:]+\): \([0-9]+\)
Below this text box, set the small drop down list labelled "File" to 2, set the drop down list labelled "Line" to 3, and set the drop down list labelled "Column" to blank. Now click on the button "OK" at the bottom of the window. This completes the creation of the compiler tool. (You can check at this point and look in TextPad's "Tools" menu to see if the tool "lcc" is at the bottom of the menu list.)
- Step 7:
- We need to create a tool in TextPad to call the lcc-win32 linker. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory
C:\lcc\bin and then in that directory double click on the program lcclnk.exe . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "lcclnk". Click on the item "lcclnk". This brings up a window where we can configure the "lcclnk" tool. In the text box labeled "Parameters:" enter the following text:
-subsystem console -o $BaseName.exe $BaseName.obj
In the text box labeled "Initial folder:" enter the following text:
$FileDir
Make sure that the check box labeled "Capture output" is checked. Now click on the button "OK" at the bottom of the window. This completes the creation of the linker tool.
- Step 8:
- We need to create a tool in TextPad that lets us run a program that we have compiled and linked. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory
C:\Windows\system32 . Double click on the program cmd.exe . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have either the item "command" or "cmd". Click on the appropriate item. This brings up the window where we can configure the tool. In the text box labeled "Parameters:" enter the following text:
/k $BaseName.exe
In the text box labeled "Initial folder:" enter the text:
$FileDir
Make sure that all the check boxes are unchecked. Now click on the button "OK" at the bottom of the window. This tool will run your C program one time and then leave you at a command prompt so that you can type other commands (you can use the "exit" command to close the console window).
Note: If your C program does not prompt the user for any input, then you can configure TextPad to capture your program's output and display it in an editor window. Change the text in the text box labeled "parameters:" to
/c $BaseName.exe
(notice that we are changing the switch /k to /c) and then check the check box labeled "Capture output". This technique can be useful for a variety of reasons, for example, you want to save the program's output, or you want an easier way to read a large amount of output, etc.
- Step 9:
- We need to create a tool in TextPad to use the Microsoft Win32 API help file that comes with lcc-win32. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Online Help File...". In the file dialog box that comes up, navigate to the directory
C:\lcc\bin and then in that directory double click on the help file win32.hlp . Now you should be back to TextPad's "Preferences" window. Click on the button "OK" at the bottom of this window. This completes the creation of the Win32 API help tool.
- Step 10:
- We need to create a tool in TextPad to use the C Runtime Library help file that comes with lcc-win32. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Online Help File...". In the file dialog box that comes up, navigate to the directory
C:\lcc\bin and then in that directory double click on the help file c-library.chm . Now you should be back to TextPad's "Preferences" window. Click on the button "OK" at the bottom of this window. This completes the creation of the C Runtime Library help tool.
- Step 11:
- When you cannot figure out what is wrong with a program that you wrote, it is nice to be able to run the program through a debugger. Lcc-win32 comes with a debugger in its IDE (see Step 2.5 above). We can create a tool for TextPad that lets us make use of this debugger. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory
C:\lcc\bin and then in that directory double click on the program wedit.exe . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "Wedit". Click on the item "Wedit". This brings up a window where we can configure the "Wedit" tool. In the text box labeled "Parameters:" enter the following text.
$BaseName.exe
Make sure that all the check boxes are unchecked. Now click on the button "OK" at the bottom of the window. After you have compiled and linked a program using the above tools, you can use this tool to run the program in the debugger from the lcc-win32 IDE.
- Step 12:
- Now it is time to test TextPad. Use your browser to download and save this very short C program, hello.c, to your computer. Use TextPad to open
hello.c . (You can use the "File -> Open" menu item in TextPad; you will need to remember where you had your browser store the hello.c file. Or, you can right click on the file hello.c and choose TextPad from the pop-up context menu.) Use the "Tools -> lcc" menu item to have TextPad run the C compiler. When the compiler tool finishes, use the "Tools -> lcclnk" menu item to have TextPad run the linker. When the linker tool finishes, use the "Tools -> cmd" menu item to have TextPad open a DOS command box at the directory containing hello.exe and run the program hello.exe . After you see the program's output, close the DOS command window and go back to TextPad and double click on the function name printf . Then use the "Tools -> wedit" menu item to have TextPad bring up the C Runtime Library help for the printf function. Close the help window and go back to TextPad. Purposely create an error in the program (delete a semicolon or misspell a name). Try to compile the program. When you get an error message from the compiler, double click on the line number in the error message. TextPad should jump to the line in the C program that the error message referred to. Fix the error, recompile, link, and use the debugger tool to open the program. Use the F4 key to single step through your program. Look in the "Debug" menu for other debugging commands. You can also right click on any source code line to call up further debugging commands (like setting a break point).
- Step 13: (optional)
- At this point, the five tools that we created have pretty unappealing names. You can use the "Configure -> Preferences..." menu item to edit these names by clicking on the word "Tools" in the left hand pane of the "Preferences" window and then clicking on a tool in the middle pane and editing the name of the tool.
- Step 14: (optional)
- In Step 1, the compile tool has the "-S" option which tells the lcc-win32 compiler to create an assembly language listing of our program. Now we will create a tool to view this listing. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools". In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory
C:\Program Files\TextPad 4 and then in that directory double click on the program TextPad.exe . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "Textpad". Click on the item "Textpad". In the text box labeled "Parameters:" enter the following text:
$BaseName.asm
In the text box labeled "Initial folder:" enter the following text:
$FileDir
Make sure that all the check boxes are unchecked. Now click on the button "OK" at the bottom of the window. (If you want, give this tool a better name.)
- Step 14.5: (optional)
- Try out the last tool by compiling a C program and then clicking on the new tool (you do not need to link a program in order to see its assembly language listing). Notice that the assembly language listing is mixed in with the original C code, so that you can see how each spedific line of C is translated into assembly language.
- Step 15:
- The result of compiling a C program is an assembly language file (an
asm file) and an object file (an obj file), and the result of linking the program is an executable file (an exe file). We have just created tools that let us see what is in the asm file. Now we will create two tools that let us see some of the internal structure of the (binary) obj and exe files.
In the left hand pane of the window that comes up, click on the word "Tools". In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory C:\lcc\bin and then in that directory double click on the program pedump.exe . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "Pedump". Click on the item "Pedump". This brings up a window where we can configure the "Pedump" tool. In the text box labeled "Parameters:" enter the following text:
/A $BaseName.obj
In the text box labeled "Initial folder:" enter the following text:
$FileDir
Make sure that the check box labeled "Capture output" is checked. Go back and click on the word "Tools" in the left hand pane of the "Preferences" window and then click on the "Pedump" tool in the middle pane and change the name of this tool to "Pedump obj".
Now for the other tool.
In the right hand pane of the "Preferences" window, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory C:\lcc\bin and then in that directory double click on the program pedump.exe . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "Pedump" (again). Click on the item "Pedump". In the text box labeled "Parameters:" enter the following text:
/A $BaseName.exe
In the text box labeled "Initial folder:" enter the following text:
$FileDir
Make sure that the check box labeled "Capture output" is checked. Go back and click on the word "Tools" in the left hand pane of the "Preferences" window and then click on the "Pedump" tool in the middle pane and change the name of this tool to "Pedump exe". Now click on the button "OK" at the bottom of the window.
- Step 16:
- In Step 11 we created a tool to use the debugger built into the lcc-win32 IDE. However, if you have Microsoft's Visual Studio 6 installed on you computer, you can use the Visual Studio debugger on executables compiled and linked by lcc. In this step we will create a tool that opens for debugging in Visual Studio an executable compiled and linked by lcc. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools". In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the following directory:
C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin
and then in that directory double click on the program MSDEV.EXE . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "Msdev". Click on the item "Msdev". In the text box labeled "Parameters:" enter the following text:
$BaseName.exe
In the text box labeled "Initial folder:" enter the following text:
$FileDir
Make sure that all the check boxes are unchecked. Now click on the button "OK" at the bottom of the window. When you use this tool, after Visual Studio 6 opens, start the debugger with the "Build -> Start Debug -> Step Into" menu item. Note: If you want to debug your C program with parameters on its command line, then click the "Prompt for parameters" check box in the Msdev tool and put the parameters in the little dialog box that pops up when you use the tool.
|
TextPad is a very powerful text editor. It has a lot of tools that make working with C, C++, Java, HTML, etc., files very easy. Editors like Notepad really pale in comparison to an editor like TextPad.
When you are editing your C source files, remember to save your work frequently (at least every 15 minutes), otherwise it may be Abort, Retry, Ignore?
|