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

2019-05-20 22:35发布

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.

5条回答
We Are One
2楼-- · 2019-05-20 23:17

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"
查看更多
相关推荐>>
3楼-- · 2019-05-20 23:21

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

查看更多
别忘想泡老子
4楼-- · 2019-05-20 23:24

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楼-- · 2019-05-20 23:28

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.

查看更多
beautiful°
6楼-- · 2019-05-20 23:30

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

查看更多
登录 后发表回答