Jan 11, 2009

Compiling a C/C++ program in Mac

One of the simplest ways to compile your program is using the program g++. You will do this using the command line (terminal). Typically, you will do the following steps:

1. 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.
2. Edit/change your program (for example, my.cpp).
3. Save your changes, remembering the folder that you put it in. For simplicity, you may want to create a MyCProgram folder directly in your hard drive (root directory)
4. From the terminal, you will make sure you're in the same directory as your .cpp file, then type g++ -o myprogram my.cpp
5. The step above compiles my.cpp (source code) into an executable called 'myprogram'. You can then run it by typing ./myprogram
6. Go to step 2 until your program works.

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.

No comments:

Carlo Cipolla's Laws of Stupidity

    "By creating a graph of Cipolla's two factors, we obtain four groups of people. Helpless people contribute to society but are...