C PROGRAMMING ¥ DAY 1 Setting Up Your Environment
How
to install and test the software, and write the Simplest C Program In The
Universe
Doug
handed out two CDs with the software to install. Next steps:
A)
Install the software
B)
Test installation
C) Test
the compiler
D) Set
up the IDE (Integrated Development Environment)
E)
Test the IDE
A)
Install the software
MSYS – Minimum
system: minimal Unix command line shell
MinGW Minimalist
GNU for Windows: GCC compiler toolset
msysDTK MSYS
Developer Tool Kit: adds telnet, rlogin, etc.
Devcpp Free
IDE (Integrated Development Environment)
mingw-insight Front-end for GNU
debugger
1) Make a folder on your drive
to hold the software to install.
2) Make sure you have
administrator access to install the software.
3) Copy the five files from the
CD to the folder you created on your drive.
4) Install MSYS-1.0.10. exe by double-clicking it
a) let it install in the defalt
location, usually, "C:\MSys\1.0"
b) if your main drive is not C:
but something else (I:, E:...) that's
ok but you'll need to do some
extra cleanup later
5) Install MinGW-3.1.0-
1.exe by
double-clicking it
a) if it asks whether you have
an older version, type 'n' and hit return
b) let it install in the
default location, usually "C:\MinGW"
6) Install msysDTK-1.0.
10.exe
a) when it asks where to
install, it will bring up a dialog box that
lists some folders. It will
have 'C:MSys' selected. Highlight
the folder named
"1.0" and then click next.
7) Install devcpp-4.9.9.
2_nomingw_ setup.exe by double-clicking it
a) you can put this anywhere
convenient, in "C:\Program Files" is ok.
b) it will complain about not
knowing where make is. ignore this for now.
8) Install mingw-insight-
6.3.exe by
double-clicking it
a) you can put this anywhere
convenient
B)
Test installation
1) Double-click
the MSys icon on the desktop. It should open a window with blue text on a white
background.
2) In this window, type 'pwd'
(just the three letters p,w,d, no quotes) and hit return. It should print something like:
"/home/[yourname] "
3) In this window, type 'which
gcc' and hit return. It probably
will return without printing anything.
4) Establishing an fstab (File
System TABles) file.
a) Type 'cd /etc' and hit
return
If you type 'pwd' and hit return, you should
see "/etc"
b) Type 'ls' and hit return
You should see a list of files. one will be
named 'fstab.sample'
c) Type 'cp fstab.sample fstab'
and hit return
d) Type 'ls' and hit return.
you should see one additional file, namely 'fstab' (File System TABles)
e) >>> If your main
drive is not "C:"
a) You will need to edit the
fstab file
b) launch 'Notepad' (probably
under the "All Programs" button in the Start button in the bar at the
bottom of the screen, if you have WindowsXP.)
c) Find the fstab file. It
should be in "X:\msys\1.0\ etc" where 'X' is the main drive. You might need to change the
"*.txt" in the open window to something else, like "*", in
order to see the fstab file
d) Edit the lines that say
"C:/MinGW /mingw" to replace the drive letter with the one you're
using. (If you installed MinGW
somewhere else, this is a way to tell MSys where it is.)
e) Save the 'fstab' file
i) If you aren't using WinXP or
somehow have an older version of Notepad, it might append '.txt' to the fstab
file. If so we'll fix it. Your system might be hiding file extensions so you
won't see this right away, but you'll find out later
5) close the MSys window.
6) reopen MSys by
double-clicking its icon
7) type 'which gcc' and hit
return. This time, it should say
something like '/mingw/bin/ gcc' If
it still says nothing, you might have a problem with the fstab file. If so,
i) type 'cd /etc' and hit
return/enter
ii) type 'ls' and hit
return/enter
iii) if you see 'fstab.txt' you
can thank Notepad for poking you
in the eye with a stick. type
'cp fstab.txt fstab' and hit
return/enter.
iv) close the MSys window and
restart again, as in step 5.
v) if it still fails, ask
someone for help
C)
Test the compiler
1) use Notepad and open a new
file called 'main.c' in the home directory under MSys. This directory is
something like 'C:\MSys\1.0\ home\myname.
2) enter the following text,
then save it:
#include <stdio.h>
int main(int argc, char *
argv[]) {
printf("Yo,
World!\n");
return 0;
}
3) go back to the Msys window
4) type 'cd ~' and hit
return/enter
5) type 'ls' and hit
return/enter
6) you should see a file called
'main.c'
i) if you see 'main.c.txt'
thank Notepad again for the sharp stick
ii) if you see nothing,
double-check Notepad to see where it is saving the file
7) type 'cpp -o main main.c'
and hit return
a) if all goes well, you should
see nothing except another prompt ('>')
i) if not, see if you can
figure out where your typo is, and try
again
ii) HINT": to re-execute
the previous command, just hit up-arrow on your keyboard. it should put the
previous command ('cpp -o...') on the command line. You can keep hitting
up-arrow to get more previous commands. once you have the right command, hit
return/enter to execute it.
b) type 'ls' and hit return
c) you should see a file listed
called 'main.exe'
i) if not, are you sure there
were no errors before? are you still
in the right directory? type
'pwd' and hit return to find out what directory you are in.
d) type 'main' and hit return
e) you should see 'Yo, World!'
print out on the command line
i) if not, get help
D) Set up the IDE
1) locate the
Dev-C++ icon and launch the program. Or if you didn't enable the icon, find the
file somehwere on your disk, wherever you installed it.
2) it will complain about not
finding 'make' etc. well, duh, you haven't told it yet. tell it to go away. it
won't, instead it will bother you again. tell it to go away again. then it will
tell you about how you should always read the 'tips'. mutter 'yeah, yeah' under
your breath and tell it to go away a third time. finally you should have the
window there.
3) find the 'tools' menu at the
top of the window. pull down that menu.
4) select the 'compiler
options' menu item
5) a window should appear
titled 'Compiler Options'.
6) there is a row of tabs at
the top of the window. click on the 'directories' tab
7) there will be a pane listing
one directory, 'C;\Dev-Cpp\ Bin"
8) below the main pane is a
small pane with a folder icon button thingy next to it. click on the thingy.
('thingy' is a technical computer science term, i'll explain it later)
9) browse until you find
'C:\MSys\1.0\ bin'. select it so it is highlighted, and click 'OK'
10) the path to the file should
appear next to the folder icon button thingy. also, but buttons below should
become enabled. click the 'Add' button
11) repeat steps 8-10 for the
'C:\MinGW\bin' folder.
12) you should now see both
folders in the window. Click OK.
E)
Test the IDE
1) Find the 'file' menu and
choose 'new>project. ..'
2) scroll down until you see
the icon for 'Empty Project'. Click on it.
the 'description' field will
fill in.
3) find the radio button that
says 'C project' and select it
4) also check the checkbox
'make default language'
5) give the project a lovely
name that it will cherish forever.
6) click OK
7) it will ask you for a
location to set the new project pick a folder that you want to use for your
personal stuff that is 'NOT' under the Dev-Cpp directory. You don't want to
delete this by accident if you stop using Dev-Cpp or upgrade it or something.
Click 'Save'
i) you can create a new folder
by clicking the 'sparkling' folder icon button thingy at the top of the 'Create
New Project' window. Rename it to what you want and select it to save the new
project in that folder.
8) select 'new>source file'
from the File menu
9) type in/copy and paste/whatever
text from the previous 'main.c' file.
10) just before the line
starting with 'return' add the following line:
getchar();
don't forget the semicolon.
11) save the file by holding
down the 'Ctrl' key and 's' key at the same time.
12) at the left is a project
icon thingy with the lovely name next to it. It should have a box with '-' in
it. click the box.
13) your new file ('cherish.c'
or whatever you named it) will appear
14) under the 'Execute' menu,
select the 'Compile and Run' item.
15) if things worked, you
should see a new window, with your lovely
greeting in it.
i) if you see a flash but no
window, you probably forgot the 'getchar()'.
ii) if you get an error, the
first line with an error should be highlighted in red. Fix it if you can figure
out what's wrong.
a) to see more about the error,
click on the 'Compile Log' button at the bottom of the window. Sometimes this
will help, sometimes it will leave you more mystified than before. life's just
that way sometimes.
16) hit return/enter to make
the window go away
i) for some folks, this doesn't
work. click in the close box (the red x at the top of the window) to make it go
away.
17) run it again and again.
show your friends. introduce your new friend with the lovely name and happy
greeting to everyone you meet.