Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Editing/Compiling Programs on Windows
Index -> Programming, C++ -> C++ Tutorials
Goto page 1, 2, 3, 4, 5, 6  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
[Gandalf]




PostPosted: Fri Jul 01, 2005 10:43 pm   Post subject: Editing/Compiling Programs on Windows

Editing/Compiling Programs on Windows Using MinGW

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

EDITORS:

There are quite a few editors for C and C++, and some which even support multiple other languages. It's up to you to figure out which one works best for you. Some of the better ones that I am aware of are:

Notepad++: Fully featured editor which supports a wide variety of languages out of the box.
http://notepad-plus-plus.org/

SciTE: Fast and lightweight cross platform editor. Supports many languages and has a nice syntax highlighting scheme.
http://www.scintilla.org/SciTE.html

Emerald Editor: Another free and easy to use, small editor. This one also supports a wide variety of programming languages and has macro capabilities. It is based on Crimson Editor, which is no longer in development.
http://www.emeraldeditor.com/

TextPad: Quite nice, but not completely free. If you want to keep this editor, you should eventually pay for it.
http://www.textpad.com
You can get the proper syntax highlighting plugin from:
http://www.textpad.com/add-ons/syna2g.html

Dev-C++: Included only for the reason that it is extremely popular, Dev C++ is not a stand alone editor, but an all out Integrated Development Environment which uses MinGW/GCC. For the purposes of this tutorial, we'll assume you're not using Dev-C++.
http://www.bloodshed.net/devcpp.html

COMPILING:

If you want to compile your source code, here is the "best", most straight-forward way. We will be working with GCC, through the Windows MinGW port, probably the most popular cross platform collection of compilers. It include compilers for C, C++, Objective C, Java as well as Ada.

First, what you need to do is download it from here:
http://sourceforge.net/projects/mingw/files/latest/download

Next, just install it, no differently than you would install any other program. You can keep all the configurations and settings as their default; that should be good enough.

Alright, this 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 you're 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 directory 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:
    gcj <nameOfFile>.java -o <nameOfFile>.exe

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

Good job! Now just go to the directory where you compiled and double click your program or run it from command prompt by typing in the executable's name. Hopefully now you will contribute to the C/C++ section and make it as popular as the Turing section. Wink
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Fri Jul 01, 2005 10:51 pm   Post subject: (No subject)

+50 bits

Could one of the mods for this section stickify this thread?
rizzix




PostPosted: Fri Jul 01, 2005 11:50 pm   Post subject: (No subject)

hmm.. ok.
1of42




PostPosted: Fri Jul 01, 2005 11:55 pm   Post subject: Re: Editing/Compiling Programs on Windows via MinGW

Nice post, but:

[Gandalf] wrote:
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.


wtf? How is it complex? You hit Ctrl+N for a new source file, and F9 to compile/run it. That was a whole 2 steps vs your 14 to compile with command line.

The only time the IDE gets complex is when you get into stuff like Projects, various optimization stuff, class browsing, parsing headers to make lists of functions, etc.

But you don't need to do that. it's all optional. At the point where you need that, you should be far advanced enough to understand it.

I mean, it's nice and all to be purist and go for the command line, but to deride well-made IDEs like Dev-C++ as bad when you're kinda wrong is pointless.

Plus, it's not even your criticism: you're just parroting wtd. Have an original thought. Rolling Eyes
wtd




PostPosted: Sat Jul 02, 2005 12:33 am   Post subject: (No subject)

Those steps are pretty much all one-time investments. You don't have to install MinGW each time you want to compile something.

Besides, the fact of the matter is that any IDE adds complexity to the process of writing the kind of simple programs that students typically write. IDEs may add convenience to the creation of larger programs, but these aren't larger programs people are writing.
[Gandalf]




PostPosted: Sat Jul 02, 2005 3:44 pm   Post subject: (No subject)

Thanks for the bits and sticky Smile.

Well, first off, this was mostly a tutorial about command line compiling, so that is why I kept the IDE section small. Dev-C++ can only do C and C++, while if you want to switch to say, Java later on then you don't need any new install or worrying about installing anything. I find it pretty handy just having command prompt open on my C++ directory and having a simple editor window open. It's easy to switch, and it doesn't require as much resources. Also, notice the quotes, I did take this from wtd, and I find it to be true. Some of the syntax-type bugs in Dev-C++ are really annoying, especially if you are new, and I don't find them in other editors.

Besides, keep in mind that I was writing this around midnight Wink.

*Edit* Another reason why I dislike Dev-C++, for some messed up reason it doesn't allow you to install to a directory with a space in the name, so I couldn't install it to C:/Program Files.
rizzix




PostPosted: Sat Jul 02, 2005 7:15 pm   Post subject: (No subject)

*sigh* may i recommend Eclipse for you Java/C/C++/PHP/Perl/Ruby/Python/Groovy/COBOL/Fortran development? ...tsk tsk tsk... Snooty
wtd




PostPosted: Sat Jul 02, 2005 9:24 pm   Post subject: (No subject)

My IDE is called "Linux". My editor is gEdit. My compiler/interpreter is bash. My integrated documentation browser is Firefox and Google. My debugger is my brain.
Sponsor
Sponsor
Sponsor
sponsor
1of42




PostPosted: Sat Jul 02, 2005 11:25 pm   Post subject: (No subject)

wtd wrote:
My IDE is called "Linux". My editor is gEdit. My compiler/interpreter is bash. My integrated documentation browser is Firefox and Google. My debugger is my brain.


And all of that could be had in 1 IDE. Rolling Eyes
wtd




PostPosted: Sun Jul 03, 2005 12:25 am   Post subject: (No subject)

1of42 wrote:
wtd wrote:
My IDE is called "Linux". My editor is gEdit. My compiler/interpreter is bash. My integrated documentation browser is Firefox and Google. My debugger is my brain.


And all of that could be had in 1 IDE. Rolling Eyes


Nawww... my brain would still need to be a separate part of the process. Smile
1of42




PostPosted: Sun Jul 03, 2005 1:45 am   Post subject: (No subject)

wtd wrote:
1of42 wrote:
wtd wrote:
My IDE is called "Linux". My editor is gEdit. My compiler/interpreter is bash. My integrated documentation browser is Firefox and Google. My debugger is my brain.


And all of that could be had in 1 IDE. Rolling Eyes


Nawww... my brain would still need to be a separate part of the process. Smile


Don't bet on it... mwahahahahaha Wink
Mazer




PostPosted: Sun Jul 03, 2005 7:29 pm   Post subject: (No subject)

rizzix wrote:
*sigh* may i recommend Eclipse for you Java/C/C++/PHP/Perl/Ruby/Python/Groovy/COBOL/Fortran development? ...tsk tsk tsk... Snooty

Well, I can't speak in regards to the other languages, but I've tried Eclipse for Python programming. The first time I tried it, I was not terribly impressed. The second time I tried it, I somehow just couldn't manage to get the PyDev installed properly even while trying several different guides each time (yes, I know there are other Python plugins available, but I'd wasted enough time already at that point).

gEdit works quite nicely. The only thing I could ask for is a little button (and/or hotkey) to call the python interpreter for the current file so that I don't need to keep a terminal open when I'm not getting any input or output from it.

And though it came with my distro already, I'm betting gEdit would be much less than an 80MB+ download Razz
wtd




PostPosted: Sun Jul 03, 2005 10:35 pm   Post subject: (No subject)

Coutsos, go into Preferences -> Plugins, and enable the Shell Command plugin. Then find it under the Tools menu. Smile
Mazer




PostPosted: Mon Jul 04, 2005 8:32 pm   Post subject: (No subject)

*wipes tear from eye* Bless you, wtd!
scuff




PostPosted: Sun Jul 24, 2005 6:17 pm   Post subject: (No subject)

I'm wanting to start some programming with OpenGL. Until now I have been using Dev-C++ as a compiler but it does not work right with the OpenGL code I got from NeHe (http://nehe.gamedev.net). Is there a better FREE compiler for this.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 6  [ 83 Posts ]
Goto page 1, 2, 3, 4, 5, 6  Next
Jump to:   


Style:  
Search: