Xcode升级后导致原Qt项目构建失败的问题

原有使用Qt Creator 4.0.2创建的跨平台GUI项目,在近日Xcode升级至8.0后,出现了构建失败的问题,错误信息如下:

clang: warning: no such sysroot directory: ‘/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk’
In file included from ../FbxVertexMerger/main.cpp:1:
In file included from ../FbxVertexMerger/mainwindow.h:4:
In file included from ../../../../Qt5.7.0/5.7/clang_64/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from ../../../../Qt5.7.0/5.7/clang_64/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /Users/wzkres/Qt5.7.0/5.7/clang_64/lib/QtWidgets.framework/Headers/qwidget.h:43:
In file included from /Users/wzkres/Qt5.7.0/5.7/clang_64/lib/QtGui.framework/Headers/qwindowdefs.h:43:
In file included from /Users/wzkres/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qglobal.h:81:
/Users/wzkres/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qsystemdetection.h:95:12: fatal error: ‘TargetConditionals.h’ file not found
# include <TargetConditionals.h>

显然,问题出在MacOSX10.11.sdk这个位置,升级后的MacOSX SDK变为了MacOSX10.12.sdk,那么如何让Qt使用新版本的SDK呢?很简单,修改Qt项目的.pro文件,加入

QMAKE_MAC_SDK = macosx10.12

然后重新构建项目就可以使用正确的SDK版本了。

UPDATE1: 切换项目至Release版后,又遇到了新的问题:

Project ERROR: Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.

查看了下Qt论坛上也发现了提到类似问题的,原因是Xcode8的/Applications/Xcode.app/Contents/Developer/usr/bin/中Qt要的xcrun变成了xcodebuild,解决方法可以在此做个xcrun的ln -s符号链接,也可以修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”)))

再次打开Qt Creator项目就不会再提示错误了。

博主友情提示:

如在您的评论中需要提及如QQ号、微信号、电子邮件地址或其他隐私敏感信息,欢迎通过>>博主专用加密工具<<加密后发布,原文只有博主可以看到。