1

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.

2
  • 1
    Try reinstalling xcode Sep 12, 2011 at 18:58
  • What is your path and what is ib /usr/bin - but easiest to reinstall XCode
    – mmmmmm
    Sep 12, 2011 at 22:45

3 Answers 3

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.

4
  • 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, 2011 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, 2011 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, 2011 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, 2011 at 3:42
2

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.

1
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .