Qt 在mac上使用证书签名并生成pkg安装包

本文详细指导如何使用Qt Creator在Mac上创建Release版本的Qt应用,包括添加依赖库、处理权限问题、签名与打包成pkg安装包,以及申请和应用开发者证书的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@[TOC](Qt 在mac上生成pkg安装包)## 标题

1、使用Qt Creator编译出Release版本

2、将生成的app程序拷贝到新的目录

3、使用macdeployqt添加依赖库

macdeployqt是qt软件自带的工具,可在安装路径中找到,
比如我的就在:~/Qt5.14.1/5.14.1/clang_64/bin/macdeployqt

右键点击生成的app,选择 Show Package Contents

未添加依赖库时

进入终端输入命令

 ~/Qt5.14.1/5.14.1/clang_64/bin/macdeployqt hippo16.app

如果该app是使用命令cp过去的,可能会在使用macdeployqt时报错,可能是权限的问题,此处我没有深究,直接用鼠标重新复制粘贴一次即可解决问题。

使用macdeployqt添加依赖库后
虽然macdeployqt帮助我们添加了大部分的依赖库,但可能还缺少了库。此时我们可以使用otool查看缺少的库。

otool -L hippo16.app/Contents/MacOS/hippo16 
strack@STRACKdeMBP csdn % otool -L hippo16.app/Contents/MacOS/hippo16 
hippo16.app/Contents/MacOS/hippo16:
	@rpath/QtMultimediaWidgets.framework/Versions/5/QtMultimediaWidgets (compatibility version 5.14.0, current version 5.14.1)
	@rpath/QtMultimedia.framework/Versions/5/QtMultimedia (compatibility version 5.14.0, current version 5.14.1)
	@rpath/QtCharts.framework/Versions/5/QtCharts (compatibility version 5.14.0, current version 5.14.1)
	@rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.14.0, current version 5.14.1)
	@rpath/QtGui.framework/Versions/5/QtGui (compatibility version 5.14.0, current version 5.14.1)
	/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1894.40.150)
	/System/Library/Frameworks/Metal.framework/Versions/A/Metal (compatibility version 1.0.0, current version 212.5.15)
	@rpath/QtNetwork.framework/Versions/5/QtNetwork (compatibility version 5.14.0, current version 5.14.1)
	@rpath/QtXml.framework/Versions/5/QtXml (compatibility version 5.14.0, current version 5.14.1)
	@rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.14.0, current version 5.14.1)
	/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
	/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 902.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)

从上面可以看到,有些库还是从系统里查找的

/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
	/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 902.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)

此时我们可以在Frameworks下新建一个文件夹 utiLib,根据上面的提示,将所需要的系统的库添加到utiLib中。

添加完第三方库后
此时我们就已经将所需要的库都打包好了,只是想要程序在其他电脑上运行,还需修改app运行时查找库的路径。

#!/bin/sh
install_name_tool -change "/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit" "@rpath/utilLib/AppKit" hippo16.app/Contents/MacOS/hippo16;
install_name_tool -change "/System/Library/Frameworks/Metal.framework/Versions/A/Metal" "@rpath/utilLib/Metal" hippo16.app/Contents/MacOS/hippo16;
install_name_tool -change "/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration" "@rpath/utilLib/DiskArbitration" hippo16.app/Contents/MacOS/hippo16;
install_name_tool -change "/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit" "@rpath/utilLib/IOKit" hippo16.app/Contents/MacOS/hippo16;
install_name_tool -change "/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL" "@rpath/utilLib/OpenGL" hippo16.app/Contents/MacOS/hippo16;
install_name_tool -change "/System/Library/Frameworks/AGL.framework/Versions/A/AGL" "@rpath/utilLib/AGL" hippo16.app/Contents/MacOS/hippo16;
install_name_tool -change "/usr/lib/libc++.1.dylib" "@rpath/utilLib/libc++.1.dylib" hippo16.app/Contents/MacOS/hippo16;
install_name_tool -change "/usr/lib/libSystem.B.dylib" "@rpath/utilLib/libSystem.B.dylib" hippo16.app/Contents/MacOS/hippo16;

此时app已经能运行了。

4、申请许可证书

首先在电脑本地申请一个证书

密钥位置:/Applications/Utilities/Keychain Access

如图所示打开申请

进入苹果开发者官网申请证书

https://developer.apple.com/account/#!/overview/76SLQT6KY4
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
选择签名在本地申请的文件,点击continue即可盛出许可,将其下载下来,再双击打开加入到密钥即可。

5、签名

给库签名

1、将Frameworks下每个文件夹(utilLib除外)下 xxx.app/Contents/Frameworks/xxx/version/5(QT版本,看自己实际情况)/Qtxxx 签名

例如:

codesign --entitlements ~/Qt5.14.1/user_app/mixer_ui/main_ui/hippo16/hippo16.entitlements  -s "3rd Party Mac Developer Application: 公司名(xxxxxxx)" hippo16.app/Contents/Frameworks/QtDBus.framework/Versions/5/QtDBus

2、给utilLib下所有文件签名
例如:

codesign --entitlements ~/Qt5.14.1/user_app/mixer_ui/main_ui/hippo16/hippo16.entitlements  -s "3rd Party Mac Developer Application: 公司名(xxxxxxx)" hippo16.app/Contents/Frameworks/utilLib/OpenGL

3、给 Plugins文件夹下所有库签名
例如:

codesign --entitlements ~/Qt5.14.1/user_app/mixer_ui/main_ui/hippo16/hippo16.entitlements  -s "3rd Party Mac Developer Application: 公司名(xxxxxxx)"  hippo16.app/Contents/Plugins/mediaservice/libqtmedia_audioengine.dylib

签名可用命令 codesign -dvvv xxx.app 查看情况

给app签名

先用xcode生成一个entitlements文件,生成一个xcode项目文件:qmake xxx.pro -spec macx-xcode
在这里插入图片描述
在xcode中编译一次,将生成的entitlements文件拷到当前文件夹即可

codesign --entitlements ~/Qt5.14.1/user_app/mixer_ui/main_ui/hippo16/hippo16.entitlements  -s "3rd Party Mac Developer Application: 公司名(xxxxxxx)" hippo16.app

打包成pkg

productbuild --component hippo16.app /Applications  --sign '3rd Party Mac Developer Installer: 公司名(xxxxxxx)' hippo16.pkg

至此,安装包就制作完成了,可以双击运行安装,也可通过命令行安装,在此我建议使用命令行安装,能看到安装的一些信息,命令如下:

sudo installer -store -pkg Joop.pkg -target /
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值