Using GCC via Xcode to Compile Base Programs

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

I installed Xcode, and I am going through the documentation to try and figure out how to use it (and I very much suspect that this has hugely affected what I am doing now) and eventually ends up in Terminal and going to "gcc [filename ] ". And I have a screen with text that starts with "Undefined Symbols" and keeps trying to reference things, so I wonder if I have connected something somewhere, especially when I'm actually in Xcode with an open program in C ++ most menu items are greyed out.

So. In really really basic terms. What am I missing and how do I fix it? Is there a basic tutorial for Xcode? Most of the documentation is for real developers, and I'm completely missing a lot of what's supposed to be done.

+2


source to share


1 answer


If Xcode is installed everything is set up correctly.

If you typed gcc on the command line, you were calling the 'C' compiler (not the C ++ compiler). This usually doesn't matter as GCC compensates by looking at the file extension. But what matters is that it doesn't call the linker with the correct C ++ flags.

What you have to do (from command line) use g ++



g++ <fileName>.cpp

      

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

g++ -o <outputName> <fileName>.cpp 

      

+1


source







All Articles