开发者

Trouble using g++ after upgrading to lion/ new xcode

开发者 https://www.devze.com 2023-03-25 10:54 出处:网络
Just upgraded to Lion from SL, and downloaded xCode from app store. I go to compile \"Hello World\" and find that g++ isn\'t being found.After some searching,I find it in /Developer/usr/bin.I add thi

Just upgraded to Lion from SL, and downloaded xCode from app store.

I go to compile "Hello World" and find that g++ isn't being found. After some searching, I find it in /Developer/usr/bin. I add this to my path, and try to compile, and now its saying it can't find io开发者_运维百科stream.

Clearly, I missed some key setup step but I don't seem to know what it is. I don't seem to remember any of this when I installed dev tools for previous mac OS upgrades. Anyone else run into this problem or offer some advice?

The code I'm compling is dirt simple obviously, file name helloworld.cpp

#include <iostream>
int main() { std::cout << "Hello World" << std::endl; }

Just trying

g++ helloworld.cpp

and its saying it can't find iostream.h (no such file or directory)

Thanks for your help.


The Xcode app just installs the IDE environment, if you want to build also from the command line then do the following:

  1. Start the Xcode IDE.
  2. From the "Xcode" menu chose "Open Developer Tool" -> "More Developer Tools..."
  3. This takes you to a download site where you can download the latest "Command Line Tools for Xcode". Download and install this and you then have the command line environment too. No need to go searching for the tools and changing your path.

Regards, Simon


What gets downloaded from the App Store is an installer for Xcode 4.1. You then need to manually run the installer. You should find it in /Applications.


I found the "installers" in 2 packages.

I executed the commands using:

open "./Install Xcode.app/Contents/Resources/Packages/DeveloperToolsSystemSupport.pkg"

and

open  "./Install Xcode.app/Contents/Resources/Packages/DevSDK.pkg"


After running the XCode installer that is downloaded by the App Store do the following:

  1. Start the Xcode IDE.
  2. From the "Xcode" menu chose "Preferences..."
  3. Select the "Downloads" section in the Preferences Pane
  4. Click install for "Command Line Tools" and you then have the command line environment too. No need to go to other web pages and manually download additional .dmg files.

(this is similar to, but simpler than, Simon's solution)


I wouldn't use gcc 4.2 from Xcode anyways. It is pretty old and not recommended anymore, especially not if you are writing C++11. For me, and for many other people I am working with, Macports worked really well. To install GCC 4.7 for example, simply set up Macports (http://www.macports.org/install.php), and then type the following command into your shell terminal:

sudo port install gcc47

which will install the compiler in your /opt/local directory by default

0

精彩评论

暂无评论...
验证码 换一张
取 消