| EECS 110: Dev-C++ Notes |
Home General Info Help |
Lectures Homework |
Dev-C++ is a free integrated development environment (IDE) for C and C++ on Windows. There are many such environments, such as Microsoft Visual Studio and Codewarrior. Any IDE can be used for this course. Most are quite similar to each other. We'll use Dev-C++ in the class examples. The teaching lab has Microsoft Visual Studio installed.
Dev-C++ can be downloaded from here.
Dev-C++ requires Windows. You need about 9 megabytes for the download file and 60 megabytes more for the installed IDE.
The instructions below should be enough to get you going. After you've installed, if you run into problems, check Aditsu's unofficial Dev-C++ FAQ.
Just to be safe, avoid using folders and file names with spaces. Don't install things in My Documents or similar. Put Dev-C++ in a simple location, such as C:\Dev-Cpp. Put your EECS 110 code in a simple location, such as C:\Courses\EECS110. Don't put your own code inside the Dev-C++ folder. You may lose your work if you have to reinstall Dev-C++.
Download the EECS 110 archive. This is a Zip archive. It's a file that contains compressed (smaller) versions of other files. Windows XP has built-in support for getting files out of Zip archives. If you have an older Windows, you can use WinZip or ZipGenius or any of a number of Zip archive utilities.
Put all the files in the archive except glut32.dll into the folder C:\Dev-C++\Templates\. (Modify this path if you put Dev-C++ somewhere else.) In Windows XP, you can just copy and paste, or drag and drop, the files in the archive to the Templates folder. If you're using a utility, use the Extract command.
Put the file glut32.dll into your Windows system32 directory. This is most likely C:\Windows\system32. If you have an older version of Windows XP or NT, it might be C:\WINNT\system32.
Create a folder (directory) in Windows where you will keep all your code, e.g., C:\Courses\EECS110\Code.
Start Dev-C++.
In Dev-C++ and most other development environments, you create a project for each application you build. A project is a small file that lists the code files needed to make the application, plus various settings for compiling those files. The steps below show how to create a project in Dev-C++. Other IDE's are very similar.
The simplest kind of project to build is one that does all its input and output in a console window, e.g., the Command Prompt window in Windows. Such programs are simple to set up, but are a bit old-fashioned.
|
Start Dev-C++, click on the File menu, then on New, then on Project .... Click on the image to enlarge it. |
|
|
The New Project dialog box will appear.
Click on the image to enlarge it. |
|
|
Dev-C++ will ask where you want to save the project. If you set the default directory correctly, you should already be in your EECS 110 code directory. Click on the "new folder" icon to create a new folder, give the folder a name, e.g., the same name as your project, wait for Windows to create the folder, then click the Open button to open that folder. Save the project file and all code files in this new folder. The project file will have a .dev extension. You can double-click that file in the future to reopen your project from Windows. Click on the image to enlarge it. |
|
|
Now you should see a project screen. The name of your project should appear in the Project Browser on the left. The template automatically creates a file main.c for this project. For many assignments, all you'll need to do is edit this file. Click on the image to enlarge it. |
|
|
Now you can type code into this window, save it, and compile it. For illustration, I've typed in a simple Hello World program. Note that the Dev-C++ editor knows about C syntax, and has colored different kinds of code differently. It also knows how to indent code. Let the editor do the work. Trust it. If something indents where you don't expect, or doesn't have the color you expect, you probably typed something wrong. Click on the image to enlarge it. |
|
|
To compile and run your program, the obvious choice is to select Compile & Run from the Execute menu, or click but even simpler, once you learn where it is, the Compile & Run icon. When you do this, Dev-C++ will ask you where you want to save the code file and what name to call it, if the file hasn't already been saved. You can call the file anything. I called mine pa1 and saved it as pa1.c in my EECS 110 code directory, but another good name would be main.c because this is the file with the main() function. Click on the image to enlarge it. |
|
|
Ooops! When I clicked the Compile & Run icon, I saw a dialog box appear indicating that the code was being compiled, and a window flashed by, but I didn't see any input. What happened? What happened was that Windows opened a Command Prompt window, ran my code, and then, because the program was done, immediately closed the window. This is a common "gotcha" with Windows. It's one of the FAQ's in the Dev-C++ Help material. The trick is to make Dev-C++ stop our program just before it calls return at the end. To do that, put your cursor anywhere on the line with the return 0. Then click on the purple Debug check mark at the bottom of the screen. A set of buttons will appear for running your program in Debug mode. Click on the image to enlarge it. |
|
|
Now when I click on Run to cursor, the window opens, shows my output, and stays open until I return to Dev-C++ and click Continue. Note: the console window might appear behind the Dev-C++ window. Just move things around to see it. Click on the image to enlarge it. |
|