目录
1、简介
想要在Mac是发布我们的Qt程序,一般要将其在X-code上编译。要使用Mac自带的编译器clang,要先安装X-code。
2、安装
安装X-code和Qt时如果碰到如下问题:
A、error: Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.
解决方案
1. 命令行输入
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
2. 命令行输入
sudo xcodebuild -license
输入 agree
3. 前往文件路径
/Users/xxxx/Qt5.7.0/5.7/clang_64/mkspecs/features/mac
编辑default_pre.prf文件,搜索xcrn,
isEmpty($$list($$system("/usr/bin/xcrun -find xcrun 2>/dev/null"))))
修改成
isEmpty($$list($$system("/usr/bin/xcrun -find xcodebuild 2>/dev/null"))))
保存退出 重新打开项目,问题解决
B、Error: Could not resolve SDK path for ‘macosx10.8’
这是原因是你当前的系统不是macosx10.8,要在Qt文件中修改。
The problem is that the online installer for Qt currently supports OSX 10.8 (Mountain Lion) by default, and I'm guessing you are on 10.9 (Mavericks) or greater.
There is a workaround:
Navigate to where you installed Qt (default /Users/your username/Qt) using finder
Go to the subdirectory 5.3/clang_64/mkspecs directory
Open the file called qdevice.pri with a text editor
Change the line !host_build:QMAKE_MAC_SDK = macosx10.8 to:
!host_build:QMAKE_MAC_SDK = macosx10.9 if you are on OS X 10.9 (Mavericks), or
!host_build:QMAKE_MAC_SDK = macosx if you are on OS X 10.10 (Yosemite)
Save the file and restart Qt Creator
我的是10.12,将 5.3/clang_64/mkspecs/qdevice.pri文件下的!host_build:QMAKE_MAC_SDK = macosx10.8改为 !host_build:QMAKE_MAC_SDK = macosx10.12 就OK啦。
3、进入正轨:
3.1、先进入到项目的pro目录
如果就一个pro文件那就在其被包含的文件夹就)
3.2、打开命令行
输入
xxxxx.pro -spec macx-xcode
3.3、编译
输入qmake的全路径 加以上的命令
3.4、出现xcodeproj文件
编译成功后,会出现Xcodeproj文件:
3.5、发布
这个文件就可以用Xcode来编译并发布了
发布脚本如下:
此脚本只是举一个例子,具体如何写需要根据需求而定