Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I used to be able to use g++ from the terminal to compile c++ programs, but now when I try to use it, I get

-bash: g++: command not found

General advice on the internet was to install XCode, but I already have XCode installed. I'm not sure what has changed since being able to use it. I'm running OSX 10.6.8 and XCode 3.2.4.

share|improve this question
1  
Try reinstalling xcode –  lemonginger Sep 12 '11 at 18:58
    
What is your path and what is ib /usr/bin - but easiest to reinstall XCode –  Mark Sep 12 '11 at 22:45

3 Answers 3

I had the same problem at one point with gcc. gcc and g++ usually link to a version-specific binary. Look in /Developer/usr/bin for something like g++-x.y, where x.y is the installed version of g++. You'll probably see gcov, gcc, etc. there as well. Just create a symbolic link from the versioned g++ to g++.

For example, on my machine, I would type ln -sf g++-4.2 g++.

Hope this helps. If the versioned compiler tools aren't there, you may need to reinstall the Developer Tools.

share|improve this answer
1  
I already have a g++ in /Developer/usr/bin. I have g++, g++-4.0 and g++-4.2. Same with gcc –  cstack Sep 13 '11 at 22:11
1  
That's very strange. What is $PATH set to? Does it include /Developer/usr/bin? If you type the absolute path (just for this exercise) /Developer/usr/bin/g++, do you still get the command not found error? –  Art Taylor Sep 13 '11 at 22:58
1  
Using the absolute path works fine. It looks like /Developer isn't in my path. How do I add that? Also, why would it be removed in the first place? –  cstack Sep 14 '11 at 2:46
    
That's actually pretty weird because I believe a proper Xcode install will also have entries for the compilers in /usr/bin. To add the /Developer binaries to your path, all you need to do is add export PATH=$PATH:/Developer/usr/bin to your .profile, .bash_profile, or .bashrc, whichever you use. grep PATH .* will show you which one you use. –  Art Taylor Sep 14 '11 at 3:42

If you have more than one account try executing g++ from the other account. If it works, you probably have an issue with the .bash path definitions.

share|improve this answer
up vote 1 down vote accepted

Okay, this is embarrassing. But reinstalling XCode from the OS X disc DID work. I just didn't think to try it because I already had it installed.

share|improve this answer
    
Not at all - this last step is fragile and still breaks for me more than I'd care to have happen. We've easily got 15 macs where upgrading to Lion sent the dev tools path astray. See Is there a second step needed to activate the command line tools? –  bmike Sep 21 '11 at 14:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.