2

When I try to compile a c++ program in my Mac terminal, I get the following error:

-bash: g++: command not found

but I believe I have all the files I need on my Mac to run the compiler. I have the Developer folder, which contains Xcode in Applications, g++ in the usr/bin folder, and a bunch of other folders.

How can I use these files to install the g++ compiler. Thank you!

user1499206
  • 25
  • 1
  • 4
  • Which version of Xcode do you have? Is there any good reason you can't upgrade to the newest version? Without knowing those two questions, it will probably take multiple rounds of guessing before anyone can come up with the right answer. – abarnert Jul 04 '12 at 00:57
  • Also, I am running OS X Lion. – user1499206 Jul 05 '12 at 15:04

3 Answers3

4

Assuming you have the latest Xcode, go to Xcode Preferences, Downloads, and click on the Install button next to Command Line Tools. This should install and put everything into your PATH automatically.

houbysoft
  • 32,532
  • 24
  • 103
  • 156
  • He obviously doesn't have the latest version of Xcode, because he has the /Developer folder, with /Developer/Applications/Xcode.app, rather than /Applications/Xcode.app, with the Developer folder buried inside of it. However, unless he tells us which version he _does_ have, it's very hard to answer, so +1 to you. – abarnert Jul 04 '12 at 00:56
3

houbysoft's answer above is correct, but the OP needs a little more detail.

The basic idea is that you need the "Command Line Tools" environment installed. But the name for that environment, and how you install it, has changed multiple times over the years. So, houbysoft's steps work for 4.3.3, but not for 3.2.6.

In the 3.2 era, the tools were called "UNIX Development". And, rather than being downloaded and installed from within Xcode, they came as part of the Xcode mpkg and were installed as part of the initial Xcode install. In most versions, there was a checkbox named "UNIX Development", usually checked by default, but in some versions it was a separate step. Looking at the "Xcode 3.2.6 and IOS SDK 4.3" disk image currently available from Apple, it's a checkbox. Anyway, that's the only officially-supported way to get them, but lots of other ways work… Here are your options:

  • Throw away Xcode 3.2.6 (just trash the whole /Developer) and install 4.3.3, then follow houbysoft's steps to get the Command Line Tools. Unless there's a good reason you can't use 4.3, this is almost certainly the best answer.
  • Throw away Xcode 3.2.6 and reinstall it, and this time make sure the "UNIX Development" checkbox is on.
  • Just re-run the 3.2.6 installer, and make sure the "UNIX Development" checkbox is on.
  • Log into developer.apple.com and look through the downloads for a package named "UNIX Development Tools", "Developer Tools CLI", "CLI Developer Environment", "Command Line Tools", or similar that corresponds to 3.2.6. There is such a package for most, but not all, versions of Xcode, and can be used to set up a command-line build environment either with or without Xcode.
  • Look at the invisible packages on the Xcode disk image. I don't remember whether you need just DeveloperToolsCLI.pkg, or that plus a few others, but a bit of trial and error or googling should get you there.
abarnert
  • 354,177
  • 51
  • 601
  • 671
0

If everything is installed correctly, it sounds like all you need to do is get your "PATH" environment variable modified.

This closely related SuperUser question should provide the answers you need, at least if you're running under Snow Leopard. Here's another question about setting environment variables for Lion.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • No, this isn't his problem. He says g++ is in /Developer/usr/bin. That isn't supposed to be on his PATH. Adding it there will appear to get past this initial problem, but all kind of other things will go wrong, and he will never get a build to work. He needs to install the Command Line Tools. – abarnert Jul 04 '12 at 00:55