Tuesday, June 14, 2005

C Compiler

I spoke to one of my relative in developing country who has a computer and Internet at home. He is going for C/C++ training but no compiler at home to practice. I know Linux will make things very very easy. I am not sure if I can convince my relative to switch his 'only computer' to Linux. That wouldn't be fair as i don't have exclusive Linux machine at home or work. So, I did a quick search of the stuff available on the internet and found this tool that should fit his current needs. The license also suits him as this can be used for free in non-commercial environment - as a student.

Visit this page and read the material and familiarize what you want and you know where to find what.
lcc-win32: A Compiler system for windows
Here is the place where you can download the bits.
Actual binary Location on the ftp server
Here is an alternate location to download. Fill out name and email (no validation is done and I don't expect spams to follow - so you should be ok even if you give a temporary info here).

The binary is almost 5 MB. Expect it to take a while if your internet is slow.

Once downloaded, open this file - accept to execute it as Windows might complain of security risk.

Accept all defaults during installation. I selected a different install directory in stead of c:\lcc. I selected the directory c:\myname\lcc. c:\myname\ is the location where I download many of my programs from internet.

After extracting the file, the program will automatically configure/compile some pieces. The exit criteria is very clear - so, don't worry about that.

One concern/pitfall is that your compiler is not set in the path. So, you have to set the path or you have to use absolute/relative path to run the compiler.

Here are the steps I followed.

Take a DOS command window (The old white characters on black window). My daughter hates this window and complains of headache when ever I open this window.

To open dos command windows, on the desktop go to Start->Run on the opened window type cmd and press enter or click OK.

assuming you installed at c:\myname\lcc

type cd c:\myname\lcc\projects
type mkdir hello
type cd hello
type notepad hello.c - you should see a text editor (notepad) open
Enter the following text in the text editor and save it

#include
int main()
{
printf("My Name\n");
}

(I would like to mention my thanks to Brian W. Kernighan and Dennis M. Ritchie for teaching me Programming language C. I took the liberty of tweaking the programe too.)

Now it is time to compile your first program.
You must now be in the directory c:\myname\lcc\projects\hello. You can check this by typing "pwd" (with no double quotes) on your dos command window.

For compiling
type ..\..\bin\lc.exe hello.c
if you did every thing fine, you should see the compiler return to the prompt with no messages.
you can ignore .exe part in lc.exe and dos would be fine.
Instead of relative path you can use absolute path like "c:\myname\lcc\bin\lc hello.c
You should include .c in hello.c program.

TO see if your program compiled fine type dir
You should see the page some thing like this

06/14/2005 11:45 AM DIR .
06/14/2005 11:45 AM DIR ..
06/14/2005 11:45 AM 61 hello.c
06/14/2005 12:18 PM 47,592 hello.exe
06/14/2005 12:18 PM 466 hello.obj
3 File(s) 48,119 bytes

(I could not make the angle brakets around DIR as my programming is not co-operating with me right now....)
if it worked fine, you can now run your first program by
type hello.exe or hello

You should notice "My Name" show up on your command window.

Send me a thanks mail and have fun programming in C. Feel free to share this joy to friends and family.

Welcome to the software programmer’s world.

---
cygwin is my personal preference and would recommend for experienced users.
Positives:
I get Unix like command line which I like.
There are lots of programs you can get under this environment
Open Source (I believe it still is really open)

Negatives:
The download is too heavy, especially on low speed internet.
You can't save the download to replicate in another place or archive.
If you want to share the executable to a friend or another computer, you got to remember to take the corresponding cygwin's dll as well.

I plan to write a similar page for Java as well. Stay tuned.
You are currently missing the IDE GUI (Integrated Development Environment). I will search around for a IDE.

If this is critical and urgent you can look for the following
TextPad - a cool text editor. you will be prompted to buy very often. It is OK if you don't buy it (hopefully for ever).
JCreator - IDE for Java - you can use this as colorful editor.

Blog Archive