MacOS - 运行app时报Library not loaded:@rapath/QtXml.framework/Versionx/5/Qtxml
问题描述
当我双击app运行时会报“Library not loaded:@rapath/QtXml.framework/Versionx/5/Qtxml”错误提示,如下图所示:
这里提示是说QtXml.framework库没有得到很好的引用,因此需要更改引用它的路径
为了检查 libraires 依赖关系,我运行了 otool -L
结果是这样的:
解决方法1
因此,使用命令 install_name_tool 来修改库的引用路径,如下所示:
注意:使用 install_name_tool 命令前先cd到app的目录下
install_name_tool -change @rpath/Qt*.framework/Versions/5/Qt* @executable_path/your/path/to/the/framework/Qt*.framework/Versions/5/Qt* /your/path/to/your/executable
示例命令:
install_name_tool -change @rpath/QtCore.framework/Versions/5/QtCore @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore Leawo\ Blu-ray\ Player.app/Contents/MacOS/Leawo\ Blu-ray\ Player
install_name_tool -change @rpath/QtGui.framework/Versions/5/QtGui @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui Leawo\ Blu-ray\ Player.app/Contents/MacOS/Leawo\ Blu-ray\ Player
现在,您已经更改了路径(您可以使用 otool -L
检查)。
解决方法2
不更改@rpath
的引用路径,直接在xcode里设置好程序的运行查找路径。如下图所示:
app里的文件目录:
补充知识:
Xcode开发动态库及Framework安装路径设置说明
1)绝对路径: 绝对路径,通常用于设置固定目录下的Framework、动态库。
2)@executable_path:执行路径,通常用于设置直接在Application中加载的FrameWork、动态库。
3)@loader_path: 加载路径,通常用于设置需要在插件中加载的FrameWork、动态库。
4)@rpath: 运行路径,通常用于设置动态库的Install Name,需要同时在调用应用中设置好rpath。
使用install_name_tool命令行工具来修改现有dylib文件的依赖
如果需要修改动态链接库的id名,可以使用命令install_name_tool -id
如果需要修改动态链接库的依赖dependents,可以使用命令install_name_tool -change
========================================================================