Editing and Compiling programs on windows via MinGW

From Compsci.ca Wiki

Revision as of 07:00, 15 December 2005 by Cornflake (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

So, you are new to C and/or C++ and you want to figure out how to get started? How to create executables? Well, here is all you need to know.

Editors

There are quite a few editors for C, C++, and some even support other programming languages.

Some I am aware of are: TextPad (recommended) - has syntax highlighting for many languages. Just get it off the website www.textpad.com (who figured) and get the proper plugin from here: http://www.textpad.com/add-ons/syna2g.html

Dev-C++ - Pretty bulky in file size IDE. "It's a buggy product, and makes the whole process far more complex than it need be." Still, if you insist, this is a pretty popular free one, and it comes with an editor and compiler. Since this one is not recommended, I will make you search for it by yourself Twisted Evil.

lccWin-32 - this one is for C, and possibly C++ (youll have to check). Do a Google search for it, it's free, and its really small and simple to use. http://www.cs.virginia.edu/~lcc-win32/

Crimson Editor - another free and easy to use, small editor. This one also supports a wide variety of languages. http://www.crimsoneditor.com/

Compiling

If you want to compile your source code, here is the best, most straight-forward way. We will be working with GCC (via MinGW) - probably the most popular compiler for all operating systems used on Windows. It can compile quite a few different languages.

First, what you need to do is download it from here: http://prdownloads.sf.net/mingw/MinGW-4.1.0.exe?download

Next, just install it, I hope you know how to do that. Just keep all the configurations and settings to default, it should be good enough.

Alright, now is the part that you need to pay attention to. To use the compiler through command prompt, you will need to edit the Windows PATH environmental variable. If you are using Windows 2000 or Windows XP then you have to: 1. Right click on My Computer from the desktop. 2. Select properties. 3. Go to advanced. 4. Click environmental variables. 5. Under system variables select Path 6. Click edit. 7. Add ; and then where you installed MinGW to. If it was C:/Program Files/MinGW then you would add ;C/Program Files/MinGW/bin to the end of what is already there, do not overwrite what is already there!

Now your done. To test to see if it worked, and compile programs, open command prompt. If you don't already have a shortcut then it should be somewhere in the accessories folder in the start menu.

When you are already there, you will see the director which you are already in. Now what you need to do is browse to where the source file is. You will be using DOS style commands, if you are not already familiar with them then: type cd/<directory> to open a folder and browse it. type cd.. to go up, 'back' into a more general directory. type dir to see what folders and files are already in the directory

Now, once you are at the location of your source file, to compile it you have to type: For C++: g++ <nameoffile>.cpp -o <nameoffile>.exe For C: gcc <nameoffile>.c -o <nameoffile>.exe For Java (not sure about this one): gcj <nameoffile>.java -o <nameoffile>.exe

This just specifies which compiler you are using, the source file, and what the outputted executable file will be called.

Tutorial written by Gandalf, moved to wiki by Cornflake

Personal tools