天天看点

MAC之Qt在Xcode8上编译错误(一)

升级到xcode8之后,安装Qt着实被坑了,出现了以下错误

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

这里提供三种解决办法:

1、如果Xcode版本低于8

很有可能是因为Xcode-select指向了这个目录“/Library/Developer/CommandLineTools.”所以我们需要的做法是将Xcode-select指向正确的路径“/Applications/Xcode.app/Contents/Developer”

step 1 先确认Xcode-select路径

1、在控制台中输入:xcode-select -print-path

2、输入:sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

3、输入:sudo xcodebuild -license 该命令一直按空格到最后输入“agree”

4、再由第一条命令确认是否修改,接着重新编译Qt工程

2、如果Xcode版本>=8

Xcode8运行xcrun命令时会去寻找xcodebuild,但是Qt的脚本还是原来的xcrun,所以需要修改文件,先进入目录

“Qt_install_folder”是指你Qt安装的路径,在你修改default_pre.prf前最好先备份一下,以防改错了,接着:

Replace:

isEmpty($$list($$system("/usr/bin/xcrun -find xcrun 2>/dev/null")))
           

With:

isEmpty($$list($$system("/usr/bin/xcrun -find xcodebuild 2>/dev/null")))
           

path如下:

diff --git a/mkspecs/features/mac/default_pre.prf b/mkspecs/features/mac/default_pre.prf
index cc8cd6.df99d1  (file)
--- a/mkspecs/features/mac/default_pre.prf
+++ b/mkspecs/features/mac/default_pre.prf
@@ -, +, @@ isEmpty(QMAKE_XCODE_DEVELOPER_PATH) {
         error("Xcode is not installed in $${QMAKE_XCODE_DEVELOPER_PATH}. Please use xcode-select to choose Xcode installation path.")

     # Make sure Xcode is set up properly
-    isEmpty($$list($$system("/usr/bin/xcrun -find xcrun 2>/dev/null"))): \
+    isEmpty($$list($$system("/usr/bin/xcrun -find xcodebuild 2>/dev/null"))): \
         error("Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.")
 }
           

3、创建连接

这是最好的办法,什么都不用修改,创建一个链接

cd /Applications/Xcode.app/Contents/Developer/usr/bin/
sudo ln -s xcodebuild xcrun