Zwe Hlaing Bwa

စိတ္ကူးတည့္ရာေရးထားေသာ ဘေလာ့ခ္

Compiling C++

Posted by Zwe on April 21, 2012

to get runtime initialization, you have to compile with

c++ testfile.cpp

which shoul result with a.out in the current directory. You can start it with


Resulting file can be renamed automatically, using

c++ testfile.cpp -o whatever

and started with


Compiling C++ on a Mac

Though the Mac isn’t officially supported at CSU, there’s probably and IDE that you can download for your Mac that looks very similar to the one we use in class. Still, one of the simplest ways to compile your program is using the program g++. You will do this using the command line (terminal), which is usually found under the ‘Applications’ folder, and then the ‘Utilities’ folder. Note, you may want to drag this onto your program bar at the bottom of the screen for future access. Typically, you will do the following steps:

Open up the terminal, as well as some kind of editor (like word pad). You can alternatively do this from the command line, but use whatever you’re comfortable with.
Edit/change your program (for example, my.cpp).
Save your changes, remembering the folder that you put it in. For simplicity, you may want to create a CSCI1301 folder directly in your hard drive (root directory)
From the terminal, you will make sure you’re in the same directory as your .cpp file, then type g++ -o myprogram my.cpp
The step above compiles my.cpp (source code) into an executable called ‘myprogram’. You can then run it by typing ./myprogram
Go to step 2 until your program works.
Note: if you’re not a Unix guru, don’t sweat it. You can change directories by typing ‘cd’ and then the directory you want to go to. If you’ve set it up correctly (by creating the csci1301 folder), before you compile the first time, you can type cd /csci1301 and you will be in the right directory.

You may want to check out the Mac site for a program called Eclipse. It seems to be pretty powerful, and I think it’s free.


2 Responses to “Compiling C++”

  1. Good article. I absolutely appreciate this website. Stick
    with it!

  2. Do you have a spam issue on this website; I also am a blogger, and I was curious about your situation; many of us have developed some nice
    procedures and we are looking to swap methods with others, why
    not shoot me an email if interested.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: