安装Xcode 4.3后无法获得MacPort功能

62

我在使用MacPorts时遇到了问题。我刚安装了OSX Lion 10.7.3,首先下载并安装了MacPorts,然后在阅读要求后,从App Store下载并安装了Xcode4.3。我启动了Xcode,它看起来是正常和可用的。但是当我尝试使用MacPorts进行端口操作时,它给了我这个错误信息(摘录):

Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.

我按照以下建议操作:

如何在OSX Lion上安装额外的Xcode软件包以使MacPorts正常工作

通过Xcode“首选项”安装了“command_line_tools_for_xcode”。然后关闭了Xcode,但仍然遇到了错误。
$ sudo port install libsocketsPassword:
Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
--->  Computing dependencies for libsockets
--->  Dependencies to be installed: openssl zlib
--->  Extracting zlib
Error: Couldn't determine your Xcode version (from '/usr/bin/xcodebuild -version').
Error: 
Error: If you have not installed Xcode, install it now; see:
Error: http://guide.macports.org/chunked/installing.xcode.html
Error: 
Error: Target org.macports.extract returned: unable to find Xcode
Error: Failed to install zlib
Log for zlib is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_zlib/zlib/main.log
Error: The following dependencies were not installed: openssl zlib
Error: Status 1 encountered during processing.

我不确定接下来该怎么做。如何排除我的Xcode和MacPort界面的问题?

17个回答

85

理论上,如果您已经安装了Xcode4.3(在/Applications中),这应该可以工作:

$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

(而且你已经安装了可选的命令行工具)


当我将Xcode从4.2更新到4.3时,这对我也起作用了;我相信如果您进行主要的操作系统更新,只需要重新安装mac-ports即可。 - Mihai Damian
1
+1。谢谢!那个被接受/评分最高的答案看起来真的很痛苦! - Otto
1
供参考,xcode-select 是苹果公司提供的工具: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/xcode-select.1.html - dkamins
此命令现在是Macports的一部分,警告:警告:您可能需要运行“sudo xcode-select -switch /Applications/Xcode.app” - Peter Ajtai
太好了!有时候可能需要运行 sudo xcode-select -switch /Developer/Applications/Xcode.app/Contents/Developer/ 命令。只需检查 Xcode 安装的位置并相应地更改命令行即可。 - Rocco
显示剩余2条评论

18

不知道为什么这个被投票否决了... 对我来说运行得非常好.. 谢谢 Pavel - Juergen Riemer
我的重新安装MacPorts直到通过Xcode偏好设置下载了命令行工具后才能正确运行。这个答案与我采取的步骤相匹配,使得MacPorts可以正常工作。 - devNoise
在尝试任何迁移之前,我下载了“命令行工具...”,并且完美地运行。Mac OS Lion + xCode 4.3.3。无需迁移。 - Ignacio Pascual
给这个点赞!对我来说有效,使用的是XCode 4.4和Mountain Lion。 - Benjamin Intal
这对我的一个相关问题进行了修复。在我升级到XCode 4.6之后,EPD ipython无法运行。安装命令行工具(从Xcode GUI中)解决了这个问题。 - Mike Ellis

11
请参考MacPorts迁移指南(适用于Xcode 4.3)
这些指南相当复杂。您需要运行xcode-select以设置新的工具路径,更新macports.conf中的developer_dir(如Henk Poley所述),重新安装MacPorts(疼痛),最后卸载并重新安装所有端口(双倍疼痛)。 编辑: 在进行以上操作后,libpvx仍无法安装。需要两个额外步骤:
  1. sudo ln -s /Developer /
  2. sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs /SDKs
如果您安装了不同的端口,则可能会有所不同!

2
我通过仅将两个软链接添加到我的根目录(在编辑中提到的Developer和SDKs)来使其工作。不需要进行macports迁移。 - plainjimbo
这些额外的信息有所帮助,最终问题得以解决。我使用以下命令更新了配置文件:sudo nano /opt/local/etc/macports/macports.conf 。非常感谢,我现在已成功使用MacPorts。 - Jason
2
这些指令比所需的更为复杂。我只是确保 xcode-select 指向正确的路径,并且 /opt/local/etc/macports.conf 中有 developer_dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain - ioquatix

10

还要在/opt/local/etc/macports/macports.conf文件中将包含developer_dir的那一行更改,使其指向/而不是/Developer


1
记得取消注释这一行代码!(默认情况下,它被 # 注释掉了) - gmcnaughton
我使用了 'sudo nano /opt/local/etc/macports/macports.conf' 来编辑配置文件,但这仍然没有解决问题,所以我遵循了 @gmcnaughton 的额外建议,最终问题得到了解决。感谢您的帮助。 - Jason
在我的 XCode 4.6 上有效。 - silentser

5

之后

sudo xcode-select -switch /Applications/Xcode.app

我也必须运行

sudo xcodebuild -license

并接受许可协议


4

这是我使用过的解决方案:

  1. Install Command Line Tools for Xcode

    Xcode -> Preferences -> Downloads
    
  2. Help MacPorts find the right Xcode folder

    sudo /usr/bin/xcode-select -switch /Applications/Xcode.app
    
  3. Create symbolic links for clang compilers as they now live elsewhere

    sudo ln -s `which clang` /Applications/Xcode.app/Contents/Developer/usr/bin/
    sudo ln -s `which clang++` /Applications/Xcode.app/Contents/Developer/usr/bin/
    

1
sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer 更合适吗?我现在就是用这种方式成功地构建macports。 - Matt
似乎会自动添加 Contents/Developerxcode-select -print-path 显示 /Applications/Xcode.app/Contents/Developer - Harish Narayanan

2
sudo mv /usr/bin/xcodebuild /usr/bin/xcodebuild.old
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild /usr/bin/xcodebuild 

2

这对我都没有用。等待macports发布一个正式支持XCode 4.3+的新版本。


2

尝试使用trunk,目前还没有支持Xcode 4.3的发布版本。


2
在/opt/local/etc/macports.conf中设置开发者路径对我来说是有效的。
developer_dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain

由于现在大多数编译器都存储在Developer下而不是/usr/bin下。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接