环境安装
- 这里没有使用
AppleBox
,参照了OSX-KVM使用qemu-system-x86_64
安装一个Virtual Hackintosh
系统来做开发.
安装Xcode
- Xcode需要
apple ID
登录后下载.
安装Homebrew
1 | ~$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
1 | brew install nghttp2 |
安装依赖库
1 | ~$ brew install nghttp2 nopoll rapidjson pkg-config |
编译源码到库
安装编译时要用的工具.
1
~$ brew install autoconf automake libtool
这里以
protobuf
为例1
2
3
4
5
6
7~$ git clone -b v2.6.0 --depth=1 https://github.com/protocolbuffers/protobuf
~$ cd protobuf && ./autogen.sh
~$ mkdir build && cd build && ../configure CC=clang CXX=clang++ CXXFLAGS="-std=c++11 -stdlib=libc++ -O3 -g" \
LDFLAGS="-stdlib=libc++" LIBS="-lc++ -lc++abi" \
--libdir=/usr/local/protobuf --includedir=/usr/local/protobuf/include --with-zlib && \
make && sudo make install
~$安装
appdmg
打包脚本1
2~$ brew install node
~$ npm install appdmg -g
库版本不兼容的问题
- 库版本不兼容的问题,因为程序是在
Catalina 10.15.17
编译构建的,而且通过brew
安装的二进制库,都是根据系统版本(Catalina)下载的,下面错误,是在High Sierra 10.13.17
下去运行,出现下面错误,这两个系统版本不兼容.
1 | dyld: lazy symbol binding failed: Symbol not found: ____chkstk_darwin |
- 处理上述问题,必须从源码去编译相应的依赖库,指定
export MACOSX_DEPLOYMENT_TARGET=10.12
变量,在Qt5
工程配置是QMAKE_MACOSX_DEPLOYMENT_TARGET
变量.
错误记录
签名权限错误
必须在
OSX
图形系统内,使用termiator
运行签名.下面是通过SSH
运行codesign
所出现的错误.1
2
3Error: Command failed: codesign --verbose --sign Developer ID Application: My Company Technology Co. Ltd. (XXXXXXXX) /Users/tuser/dailybuild_mac/felo-client-mac-2021.19.137.dmg
/Users/tuser/dailybuild_mac/felo-client-mac-2021.19.137.dmg: errSecInternalComponent通过下面操作终端(shell)导入签名证书.再试试看,再尝试通过
SSH
去签名,看是否成功.1
2
3~$ sudo security import developer_id.p12 -k /Library/Keychains/System.keychain -P "<your password>" -T /usr/bin/codesign
# must run below in the shell.
~$ security unlock-keychain下面这个错误也是类似,只是现在Linux下.QT程序内调用
root
权限,通过远程ssh -X
运行的GUI
程序会有下面错误,而在它的本机上面确不会,如,使用pkexec
运行,会调出一个输入密码的窗口.1
Error creating textual authentication agent: Error opening current controlling terminal for the process (`/dev/tty'): No such device or address
打包错误
- 下面的错误,要确认主工程内的
info.plist
文件里的CFBundleExecutable,CFBundleName
节点值,是否与bundle
名称对应,是否与主工程.pro
里的TARGET
对应.
1 | ~$ macdeployqt output/myappqt.app |
macdeployqt
错误1
2ERROR: no file at “/usr/local/opt/libiodbc/lib/libiodbc.2.dylib”
ERROR: no file at “/Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib”上面错误是缺失两个依赖的库,须要安装下面支持
1
2
3
4
5
6~$ brew install libiodbc postgres
~$ sudo mkdir -pv /Applications/Postgres.app/Contents/Versions/9.6
~$ sudo ln -svf /usr/local/Cellar/postgresql/13.3/lib /Applications/Postgres.app/Contents/Versions/9.6
/Applications/Postgres.app/Contents/Versions/9.6/lib -> /usr/local/Cellar/postgresql/13.3/lib不能加载插件的错误,如果不是从终端(shell)打开目标程序,就表显为程序闪退.终端打开运行显示如下:
1
2
3
4
5qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: cocoa.上面错误信息,只是初步定位了错误,如果是在
Linux
下,上面错误基本是因为文件不存造成.这里打开export QT_DEBUG_PLUGINS=1
,查看如下:1
2
3
4
5
6
7
8
9
10
11
12Got keys from plugin meta data ("cocoa")
QFactoryLoader::QFactoryLoader() checking directory path "/Applications/MyApp.app/Contents/MacOS/platforms" ...
Cannot load library /Applications/MyApp.app/Contents/Plugins/platforms/libqcocoa.dylib: (dlopen(/Applications/MyApp.app/Contents/Plugins/platforms/libqcocoa.dylib, 133): no suitable image found. Did find:
/Applications/MyApp.app/Contents/Plugins/platforms/libqcocoa.dylib: code signature in (/Applications/MyApp.app/Contents/Plugins/platforms/libqcocoa.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)
QLibraryPrivate::loadPlugin failed on "/Applications/MyApp.app/Contents/Plugins/platforms/libqcocoa.dylib" : "Cannot load library /Applications/MyApp.app/Contents/Plugins/platforms/libqcocoa.dylib: (dlopen(/Applications/MyApp.app/Contents/Plugins/platforms/libqcocoa.dylib, 133): no suitable image found. Did find:\n\t/Applications/MyApp.app/Contents/Plugins/platforms/libqcocoa.dylib: code signature in (/Applications/MyApp.app/Contents/Plugins/platforms/libqcocoa.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)"
qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: cocoa.
Abort trap: 6如上所示,在
OSX
下出现的Could not load the Qt platform plugin
是因为文件未签名造成的.使用下面方法尝试处理.1
~$ codesign -f -s "Mac Developer: 你的开发者邮箱" /usr/local/opt/*/lib/*.dylib
签名问题
检验签是否正确
1
2
3~$ spctl -a -t exec -vv /Applications/MyApp.app
/Applications/MyApp.app: nested code is modified or invalid查看具体签名错误详情
1
2
3
4
5~$ codesign --verify --deep --verbose dmg_root/MyApp.app
dmg_root/MyApp.app: nested code is modified or invalid
In subcomponent: /Users/user/myapp-desktop/build-myappqt-Desktop_x86_darwin_generic_mach_o_64bit-Release/dmg_root/MyApp.app/Contents/Frameworks/QtWebEngineCore.framework
file modified: /Users/user/myapp-desktop/build-myappqt-Desktop_x86_darwin_generic_mach_o_64bit-Release/dmg_root/MyApp.app/Contents/Frameworks/QtWebEngineCore.framework/Versions/Current/Helpers/QtWebEngineProcess.app签名后,检验将要打包的
bundle
目录签名情况,直到出现下面这样正确为止.1
2
3
4~$ codesign --verify --deep --verbose dmg_root/MyApp.app
dmg_root/MyApp.app: valid on disk
dmg_root/MyApp.app: satisfies its Designated Requirement如果按上述签名成,但是其它机器上安装成功,运行时确崩溃了,有些系统会有
DiagnosticReports
,有些是直接闪退.下面DiagnosticReports
的错误,关键信息是EXC_BAD_ACCESS (Code Signature Invalid)
,__TEXT
字段处是指向libcrypto.1.1
,可以对libcrypto.1.1
路径的文件进行签名校验查看.用户程序crash
出错的路径是在/Users/<username>/Library/Logs/DiagnosticReports
下面.
1 | Time Awake Since Boot: 12000 seconds |
- 下面要是目标程序的未完整签名造成的.
__TEXT
指向当前系统的/usr/lib/dyld
.
1 | Crashed Thread: 0 Dispatch queue: com.apple.main-thread |
OSX
编译链接的错误问题, 是因为缺少了这个架构的库文件1
2
3
4
5
6
7
Undefined symbols for architecture x86_64:
"_iconv_ostream_create", referenced from:
-exported_symbol[s_list] command line option
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
OSX命令行操作
重启服务
1 | lcy@lcys-iMac-Pro ~ % sudo launchctl stop com.openssh.sshd |
- 或者
1 | lcy@lcys-iMac-Pro ~ % sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist |
使用apple
脚本开启远程管理(VNC桌面访问)
1 | #!/bin/zsh |
osascript
是调起一个图形授权窗口,类似于终端的sudo
,在Windows
下就类似是UAC
窗体,在Linux
下就是调用pkexec
获取sudo
权限.
Command Line 修改配置(defaults)
枚举出所有的可配置域.
1
2
3sudo defaults domains
com.apple.AppleMultitouchMouse, com.apple.AppleMultitouchTrackpad, com.apple.CoreBrightness, com.apple.CoreGraphics, com.apple.CrashReporterSupportHelper, com.apple.MobileAsset, com.apple.SSMenuAgent, com.apple.SoftwareUpdate, com.apple.UserAccountUpdater, com.apple.WirelessRadioManager.debug, com.apple.airplay, com.apple.awdd.persistent, com.apple.bluetoothd, com.apple.corecaptured, com.apple.coreduetd, com.apple.das.fairscheduling, com.apple.driver.AppleBluetoothMultitouch.mouse, com.apple.driver.AppleBluetoothMultitouch.trackpad, com.apple.driver.AppleHIDMouse, com.apple.dt.xcodebuild, com.apple.icloud.findmydeviced, com.apple.icloud.searchpartyd, com.apple.java.util.prefs, com.apple.loginwindow, com.apple.mediaremote, com.apple.mediaremoted, com.apple.rtcreporting, com.apple.security.ctkd-db, com.apple.systempreferences, com.apple.systemstats.microstackshot, com.apple.tailspin, com.apple.universalaccess, com.apple.xpc.activity2, com.oracle.javadeployment, systemmigrationd查看一个域的配置.
1
2
3
4
5
6
7
8
9
10
11
12
13~$ sudo defaults export com.apple.systempreferences -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AttentionPrefBundleIDs</key>
<dict>
<key>com.apple.preferences.softwareupdate</key>
<integer>1</integer>
</dict>
</dict>
</plist>查看一个文件的配置.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25~$ sudo defaults export /Library/Preferences/com.apple.RemoteManagement.plist -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>-bool</key>
<string>no</string>
<key>ARD_AllLocalUsers</key>
<true/>
<key>ARD_AllLocalUsersPrivs</key>
<integer>1073742079</integer>
<key>AllowSRPForNetworkNodes</key>
<false/>
<key>DisableKerberos</key>
<false/>
<key>LoadRemoteManagementMenuExtra</key>
<true/>
<key>ScreenSharingReqPermEnabled</key>
<false/>
<key>VNCLegacyConnectionsEnabled</key>
<true/>
<key>allowInsecureDH</key>
<true/>
</dict>
</plist>读取域内的一个键值
1
2sudo defaults read /Library/Preferences/com.apple.RemoteManagement.plist ARD_AllLocalUsers
1写入一个键值
1
sudo defaults write /Library/Preferences/com.apple.RemoteManagement.plist RestoreMachineState -bool no
keychain
密码访问SUDO
Why do I sometimes have to log in twice when connecting to my Mac?
https://brettterpstra.com/2021/04/06/scripting-with-sudo-on-mac/
https://bunchapp.co/docs/integration/advanced-scripting/sudo/去掉VNC的登录密码输入.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30sudo defaults write /Library/Preferences/com.apple.RemoteManagement VNCAlwaysStartOnConsole -bool true
Password:
lcy@lcys-iMac-Pro ~ % sudo defaults export /Library/Preferences/com.apple.RemoteManagement -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>-bool</key>
<string>no</string>
<key>ARD_AllLocalUsers</key>
<true/>
<key>ARD_AllLocalUsersPrivs</key>
<integer>1073742079</integer>
<key>AllowSRPForNetworkNodes</key>
<false/>
<key>DisableKerberos</key>
<false/>
<key>LoadRemoteManagementMenuExtra</key>
<true/>
<key>ScreenSharingReqPermEnabled</key>
<true/>
<key>VNCAlwaysStartOnConsole</key>
<true/>
<key>VNCLegacyConnectionsEnabled</key>
<true/>
<key>allowInsecureDH</key>
<true/>
</dict>
</plist>
查找OSX的服务运行参数
1 | ~$ launchctl list | grep "RemoteDesktop" |
1 | ~$ launchctl print system/com.apple.remotemanagementd |
谢谢支持
- 微信二维码: