Mac下发布Qt
周六在公司折腾一天Mac下发布Qt程序,搞的一头雾水,今天又研究了半天,终于搞定了,记录操作步骤,备忘。
软件版本:
Qt 5.7
Qt程序调用了第三方库;
Mac下发布Qt程序
Mac中的GUI应用必须以Bundle的形式运行,所谓Bundle,是一个以”.app”结尾命名的文件夹,系统自动识别它为一个应用包,应用所有的东西(执行文件、链接的动态库、资源文件等等)都在里面了,打开应用直接”open myApp.app”就可以了,安装的时候直接把Bundle拖到Finder里就行了。卸载的时候直接把Bundle删除就行了。
- 这里的App 名字指的是 intelligent-detective
Qt第一次运行构建后,会在构建目录下生产 intelligent-detective.app 文件和一系列的 xx.o 文件
- 进入到 构建目录下,
cd release
- 查看该app所需的依赖库
otool -L intelligent-detective.app/Contents/MacOS/intelligent-detective
- 把所需要的依赖库拷入该app的Frameworks目录
因为我也不知道各个库的作用,就把全部的都拷进去了
cp -R ~/Qt5.7.0/5.7/clang_64/lib/ intelligent-detective.app/Contents/Frameworks
- 使用 macdepolyqt 进行打包
macdeployqt intelligent-detective.app
会出现类似以下的错误
ERROR: no file at “/lib/libopencv_core.3.1.dylib”
以下两种方式不确定那种方式使其生效
4.1. 创建该目录, 并把动态链接库拷贝到该文件夹下。
cd /
sudo mkdir lib
sudo chmod 777 /lib/
cp /usr/local/lib/libopencv_core.3.1.dylib /lib/
4.2. 将链接库修改成它的绝对路径
install_name_tool -change “libopencv_core.3.1.dylib” “/usr/local/lib/libopencv_core.3.1.dylib” intelligent-detective.app/Contents/MacOS/intelligent-detective
再次执行打包即可。
添加图标
- 在配置文件 intelligent-detective.pro 中添加
ICON = intelligent-detective.icns
- 在项目的主目录下添加图片
intelligent-detective.icns
- 编译运行并查看配置文件
nano intelligent-detective.app/Contents/Info.plist
< key>CFBundleIconFile</key>
< string>intelligent-detective.icns</string>