不支持的Mach-O文件类型(仅MH_OBJECT和 MH_DYLIB可以被链接)
我正在把一个项目从Qt5转换到macOS上的Qt6.11,使用QMake。
我的.PRO文件指定了:
QT += core gui help uitools widgets printsupport network xml sql
Platforms.files += $$(QTDIR)/plugins/platforms/libqcocoa.dylib
Styles.files += $$(QTDIR)/plugins/styles/libqmacstyle.dylib
Imageformats.files += $$(QTDIR)/plugins/imageformats/libqico.dylib \
$$(QTDIR)/plugins/imageformats/libqgif.dylib \
$$(QTDIR)/plugins/imageformats/libqjpeg.dylib \
$$(QTDIR)/plugins/imageformats/libqsvg.dylib
QTDIR解析为:
/Users/me/Qt6/6.11.1/macos
我遇到了以下错误:
unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in '../MyApp.app/Contents/Plugins/platforms/libqcocoa.dylib'
unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in '../MyApp.app/Contents/Plugins/imageformats/libqico.dylib'
unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in '../MyApp.app/Contents/Plugins/styles/libqmacstyle.dylib'
unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in '../MyApp.app/Contents/Plugins/imageformats/libqgif.dylib'
unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in '../MyApp.app/Contents/Plugins/imageformats/libqjpeg.dylib'
unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in '../MyApp.app/Contents/Plugins/imageformats/libqsvg.dylib'
unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in '../MyApp.app/Contents/Plugins/sqldrivers/libqsqlite.dylib'
为什么Qt要对它自己的动态链接库提出异议?我在编译前会删除MyApp.app文件夹。它是在编译阶段构建的,推测这些.dylib来自QTDIR?
我该如何让它完成链接?
解决方案
我问了ChatGPT,解决方案是在.PRO文件中删除以下几行:
PrintSupport.files += $$(QTDIR)/plugins/printsupport/libcocoaprintersupport.dylib
PrintSupport.path = Contents/Plugins/printsupport
Platforms.path = Contents/Plugins/platforms
Platforms.files += $$(QTDIR)/plugins/platforms/libqcocoa.dylib
Styles.path = Contents/Plugins/styles
Styles.files += $$(QTDIR)/plugins/styles/libqmacstyle.dylib
Imageformats.path = Contents/Plugins/imageformats
-L"MyApp.app/Contents/Plugins/platforms" -lqcocoa \
ChatGPT提醒我如下:
"在macOS的 Qt6中,插件二进制文件不再是普通的.dylib文件"
"让Qt部署这些插件。"
"你的链接器明确地尝试将插件链接到可执行文件中。"
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。