views:

527

answers:

1

So, I'm a brand new CS student, on a Mac, and I'm learning C++ for one of my classes. And I have a dumb question about how to compile my super basic C++ program.

I installed Xcode, and I'm looking through the documentation to try and figure out how to use it (and I highly suspect it's extremely overpowered for what I'm doing right now) and eventually end up going into Terminal and going "gcc [filename]". And I've got a screen full of text that starts with "Undefined Symbols", and goes on about trying to reference things, so I'm wondering if I didn't hook up something somewhere, especially as when I'm actually in Xcode with a C++ program open, most of the menu items are greyed out.

So. In really really basic terms. What did I miss doing, and how do I fix it? Is there a basic guide to Xcode? Most of the documentation is aimed at real developers, and I'm totally missing a lot of what is being assumed.

+1  A: 

If XCode is installed then everything is set up correctly.

If you typed gcc on the command line then you invoked the 'C' compiler (not the C++ compiler). Usually this does not matter as GCC compensates by looking at the file extension. But what does matter is that it does not invoke the linker with the correct C++ flags.

What you should do (from the command line) is use g++

g++ <fileName>.cpp

By default the output file is a.out and placed in the same directory.
g++ has a flag to specify a different output name -o

g++ -o <outputName> <fileName>.cpp
Martin York
That would explain a lot-- but when I tried it, Terminal just gives me a new line. No error, nothing. (It's a program that asks for several inputs, and should return an output, and this I've tested on a different computer.)
KLR
@KLR: You realize that GCC/G++ will just compile the program, right? It doesn't run the program for you. If you haven't supplied an output name, it will call the compiled program "a.out".
Chuck
Well. I feel dumb now. Okay, so will the compiled program be in the same directory as the original file? And how do supply an output name?
KLR