Compiling c++ in terminal

May 24, 2011 at 6:28pm
I just upgraded to Mac OS X 10.6.7 and now using the command

g++ xxx.cpp -o xxx

to compile isn't working.

What do I do?
May 24, 2011 at 6:30pm
Are you getting an error message?

Do you have gcc installed? Do you have g++ appropriately aliased to the relevant gcc command (depending on setup, this one is)?

Do you have g++ on your path? What output do you get for "which gcc" and "which g++"?
Last edited on May 24, 2011 at 6:32pm
May 24, 2011 at 6:53pm
It says "command not found".

Is it installed? When I search gcc through spotlight I see a gcc (MacOSX.10.5.sdk). I assumed that it was installed automatically with the upgrade. I did install Xcode before I ever started compiling perhaps gcc is included with that?

I searched for gcc 10.6 on apple.com and found nothing.

When I compile it is from within the directory of the file I am trying to compile.


I just tried "which g++" and it seemed to work but when I tried to run the program after

which g++ xxx.cpp -o xxx
./xxx
(No such file or directory).

Should I updated to the latest version of Xcode?
May 24, 2011 at 7:20pm
Hello,

mschott21, please post the answer to the following commands (go to the directory with your cpp file):
1) g++
2) g++ -c xxx.cpp
3) g++ -o executable.out xxx.o
4) ./executable.out

I have Debian linux and my outputs are like soȘ
1) g++: no input files
2) nothing
3) nothing
4) the output of my program.
May 24, 2011 at 7:27pm
1. command not found
2. command not found
3. command not found
4. does not exist

Is there an updated version of gcc that I need to install? If so I can't find it on developer.apple.com unless its in the Xcode 4 package which costs $$$. I am stuck.
Last edited on May 24, 2011 at 7:38pm
May 24, 2011 at 7:38pm
I'm glad you got your program working.
In linux, witch command returns the path to the executable, maybe try to check if the path console variable is set corectly. In bash I would do " echo $PATH$".
May 24, 2011 at 7:44pm
I thought it was working but I really was just running the executable file i created before. I really don't know how to create an executable now. I'll try to check the path but I don't know how to fix anything and I am not confident in my ability to recognize an error.
Last edited on May 24, 2011 at 7:46pm
May 24, 2011 at 7:48pm
It sounds like you simply haven't got it installed, or it's not on your path (i.e. cannot be found when you try to run it).
May 24, 2011 at 8:04pm
And what would be the correct path?
(home)/documents/c++_files is my directory location
May 24, 2011 at 8:05pm
On my system, gcc lives in /usr/bin/

I've no idea about yours.
Topic archived. No new replies allowed.