GCC on Mac...unable to find

I am talking a course in C++. I was told that GCC 4.0 exists on the mac. It comes under Xcode. But I am unable to find this compiler to run my C++ code. In fact I download Xcode and reinstalled it. To search for GCC I did the following:

--Open Xcode
--File > New Project

I do not find GCC in the list of things there are...How do I open C++ compiler on the mac and run my programs? Please help!

MacBook Pro 2.16 GHz (Core 2 Duo), 4 GB RAM, 120 GB HDD, Mac OS X (10.5.2)

Posted on Mar 6, 2008 8:16 AM

Reply
4 replies

Mar 6, 2008 10:52 AM in response to Trillianx

No. GCC is only a compiler. If you need an editor, try TextWrangler. It's free. Better still, use Xcode, Apple's free Integrated Development Environment (IDE). It will invoke "gcc" for C programs (you write), and "g++' for C++ programs.

Technically, GCC is not in Xcode. GCC is a program (one of many) invoked when you compile your program. Xcode "knows" what program / command to invoke by looking at the file extension (.c = C program, .cc or .cpp = C++ program, .m = Objective-C, etc).

You can trace GCC's lineage back to its UNIX roots, where the closest thing to an IDE is Emacs. After all, Mac OS X is just a pretty face on top of BSD UNIX. IDEs are great, but knowing how to use vi and emacs, make files and command-line compilers is what (all?) programmers should learn (IMHO).

Try this on your command line / terminal:
cat>hello.c
#include <stdio.h>
int main()
{
printf("Hello, world.\n");
return 0;
}
<Ctrl-D>
gcc -o hello hello.c
./hello

The "cat" command takes whatever you type and redirects it to a file named "hello.c".
Hitting Control-D in your terminal means end-of-file (it closes the "hello.c" file).
The following command, gcc, compiles "hello.c", creating an executable program named "hello".
The final command "./hello" runs your program. It should say "Hello, world." and terminates.
Congratulations! You just created and ran the obligatory Hello program.

To debug a program, use "gdb". Again, using Xcode would simplify things. Like "gcc", "gdb" is a command-line program, but Xcode putd a pretty interface on it. Again, it'd probably be a good idea to learn how to use "gdb" in all its native, command-line glory.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

GCC on Mac...unable to find

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.