我刚刚安装了 Qt 5.5,并且第一次在 OS X 上使用 Qt Creator。当我第一次安装 Qt 时,它给了我一条错误消息“未安装 Xcode 5”,我认为这很奇怪,(我有 Xcode 7 beta) ,但无论如何安装成功完成。
现在,当我启动或打开一个项目时,我收到错误:
项目错误:Xcode 未正确设置。您可能需要通过运行 /usr/bin/xcodebuild 来确认许可协议。
当我在终端中运行 /usr/bin/xcodebuild
时,我得到以下信息:
xcode-select:错误:工具“xcodebuild”需要 Xcode,但活动开发者目录“/Library/Developer/CommandLineTools”是命令行工具实例
我不确定 Xcode 与 Qt Creator 有什么关系,除非它与访问库以实现跨平台兼容性有关,但有没有办法解决这个问题?
>= Xcode 8
正如布鲁斯所说,在 Xcode 8 中,当 Qt 试图找到 xcrun
而应该寻找 xcodebuild
时,就会发生这种情况。
打开文件:
Qt_install_folder/5.7/clang_64/mkspecs/features/mac/default_pre.prf
代替:
isEmpty($$list($$system("/usr/bin/xcrun -find xcrun 2>/dev/null")))
和:
isEmpty($$list($$system("/usr/bin/xcrun -find xcodebuild 2>/dev/null")))
~> Xcode 8
在 Xcode 8 之前,安装 Xcode 后安装命令行工具时会出现此问题。发生的情况是 Xcode-select
开发者目录指向 /Library/Developer/CommandLineTools
。
使用以下命令将 Xcode-select
指向正确的 Xcode Developer 目录:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
使用以下命令确认许可协议:
sudo xcodebuild -license
这将提示您通读许可协议。
输入 agree
接受条款。
如果您更改 Qt_install_folder/5.7/clang_64/mkspecs/features/mac/default_pre.prf
的内容,则它仅适用于桌面套件,不适用于 ex。模拟器。
更好的方法是创建符号链接:
cd /Applications/Xcode.app/Contents/Developer/usr/bin/
sudo ln -s xcodebuild xcrun
因此您不必更改所有目标的 .prf 文件。
这可以解决问题:
#sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
在您的终端中运行它。
对于 Xcode 8 的用户来说,还有另一个问题。在 Qt 5.7.1 发布之前,请参阅此处获取临时解决方案:
https://forum.qt.io/topic/71119/project-error-xcode-not-set-up-properly
总结一下:
在文本编辑器中打开 Qt_install_folder/5.7/clang_64/mkspecs/features/mac/default_pre.prf
,并将其替换:
isEmpty($$list($$system("/usr/bin/xcrun -find xcrun 2>/dev/null"))))
有了这个:
isEmpty($$list($$system("/usr/bin/xcrun -find xcodebuild 2>/dev/null")))
如果您使用 XCode 8.x 从源代码构建 Qt,则必须在第 551 行更改文件 qt-everywhere-enterprise-src-5.7.0/qtbase/configure
中的“-find”参数,使其看起来像:
if ! /usr/bin/xcrun -find xcodebuild >/dev/null 2>&1; then
设法解决它安装完整版的 Xcode,同意条款,然后使用 xcode-select --reset
。
基本上问题是您指向 /Library/Developer/CommandLineTools
的 xcode 不允许您接受条款 &条件。所以安装后&重置位置,应该没问题
对我来说,正确工作的唯一方法是用“#”注释关于 xcrun 的行:
# Make sure Xcode is set up properly
#isEmpty($$list($$system("/usr/bin/xcrun -find xcrun 2>/dev/null"))): \
#error("Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.")
在文件:Qt_install_folder/5.7/clang_64/mkspecs/features/mac/default_pre.prf
只是为了本着“这对我有用”的精神添加一些旧答案,我发现通过启动 Xcode,登录到我的开发人员帐户(只是一个免费帐户),然后在“位置”中设置命令工具.我可以得到
'sudo /usr/bin/xcodebuild -license 同意'
去工作。即它在命令行中启动了一个同意过程,我在仔细阅读了所有 14 个 squillion 页的内容后同意了。
我不必编辑任何东西。
我的系统是 Mojave 10.14.6 和 Xcode 10.3 (10G8)。
/usr/local/Cellar/qt@5.5/5.5.1/mkspecs/features/mac/default_pre.prf
找到了相关的default_pre.prf
文件。我还尝试了 Rudolf Ratusiński 的方法,虽然它让我克服了第一个困难,但后来却导致了许多虚假信息,而当我使用这种方法时我没有得到这些信息。