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

只愿长相守 提交于 2019-12-07 18:50:44

问题


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 iostream.

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.


回答1:


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.




回答2:


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




回答3:


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"



回答4:


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)




回答5:


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



来源:https://stackoverflow.com/questions/6891841/trouble-using-g-after-upgrading-to-lion-new-xcode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!