我正在从事Qt项目。我已经成功安装了QJson。并且已经使用解析器来解析数据。我的代码编译成功,但在运行时它给了我以下错误:
dyld:库未加载:libqjson.0.dylib
引用自:/Users/sanjay/untitled1-build-desktop-Qt_4_8_3_in_PATH_System_Debug/untitled1.app/Content/MacOS/untitled1
原因:找不到图像
我已经在Qt创建器中添加了库作为外部库。它将以下代码添加到我的 .pro 文件中:
macx: LIBS += -L$$PWD/../build/_preferred_path_/lib/-lqjson
包含路径 += $$PWD/../build/_preferred_path_/include/qjson
依赖路径 += $$PWD/../build/_preferred_path_/include/qjson
谁能告诉我我做错了什么?
确保库位于应用程序的应用文件旁边。给出完整的路径名,如 LIBS += "lib/libqjson.dylib"
我使用了上述指令,它对我有用。
如果您的应用程序编译成功,则意味着 pro 文件中定义的项目配置是正确的(包括 LIBS 配置)。
在这种情况下,您的应用程序在运行时失败,因此这意味着在库路径中找不到libqjson.0.dylib。首先使用 otool 工具 (http://tech-queries.blogspot.com/2011/04/dynamic-library-dependency-on-mac-os-x.html) 检查 json 库如何与您的库链接。此工具将帮助您检测问题,检测到后您可以:
- 将libqjson.0.dylib复制到适当的位置
- 使用install_name_tool工具 http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/install_name_tool.1.html 正确链接
库步骤的重新链接可以在PRO文件中设置为构建后步骤。下面是示例:
macx {
QMAKE_POST_LINK = install_name_tool -change libqjson.0.dylib @loader_path/relative_path_to_library/libqjson.0.dylib your_binary_file
在"终端"中,键入以下内容:
otool -L /Users/sanjay/untitled1-build-desktop-Qt_4_8_3_in_PATH_System_Debug/untitled1.app/Contents/MacOS/untitled1
它将告诉您每个依赖库的预期位置。