【问题标题】:dylib library path and use it in applicationdylib 库路径并在应用程序中使用它
【发布时间】:2015-11-23 14:54:16
【问题描述】:

我想在 Mac OS X El Capitan (10.11.x) 中创建一个库,并在 qt creator 的另一个应用程序中使用它,所以我在 qt 中使用此设置创建了一个简单的库:

QT       -= gui
TARGET = /System/Library/Frameworks/MyFrm.framework/dylib/DynminLinkingLib
TEMPLATE = lib

如您所见,我在 MyFrm 框架中创建了“DynminLinkingLib”库;之后我创建了一个 Qt 应用程序来使用该库。

QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SampleProject
TEMPLATE = app
macx: LIBS += -L/System/Library/Frameworks/MyFrm.framework/dylib -lDynminLinkingLib.1.0.0
INCLUDEPATH += /System/Library/Frameworks/MyFrm.framework/include

当我在 qt 中运行我的应用程序时,它给了我这个错误:

dyld: Library not loaded: libDynminLinkingLib.1.dylib
  Referenced from: /Users/mac/Src/dll/DynamicLinking/build-SampleProject-Desktop_Qt_5_5_0_clang_64bit-Debug/SampleProject.app/Contents/MacOS/SampleProject
  Reason: image not found
The program has unexpectedly finished.

为了解决 Qt 项目中的这个错误,我将 DYLD_LIBRARY_PATH 变量设置为 /System/Library/Frameworks/MyFrm.framework/dylib 并且效果很好,但是当我运行捆绑应用程序时它不起作用并给我这个错误:

enter image description here

这是因为“libDynminLinkingLib.1.dylib”不在应用程序路径中。

otool -D /System/Library/Frameworks/MyFrm.framework/dylib/libDynminLinkingLib.1.0.0.dylib
libDynminLinkingLib.1.dylib

我有两个问题:

  1. 我知道如何通过install_name_tool 解决这个问题,但我想在 qmake 和 .pro 文件中解决这个问题。那么如何通过 pro config 文件解决这个问题呢?

  2. 在 El Capitan 中,出于安全原因,我无法使用 DYLD_LIBRARY_PATH。为了使用它,我必须停用 SIP(​​系统完整性保护)。那么有什么方法可以在不停用 SIP 的情况下使用 DYLD_LIBRARY_PATH 吗?

【问题讨论】:

  • "我知道如何配置这个问题,但是 install_name_tool " - install_name_tool 是解决问题的正确方法。我不相信你可以通过 Qt Creator 或在 .pro 中做到这一点
  • LIBS+= -L path -l filename 指令会导致版本问题。使用第一个 LIBS+= /absolute-path-to-my-dylib。不要使用符号链接而只使用物理位置。必要时重命名。之后,您可以使用 -L -l 指令

标签: macos osx-elcapitan dylib otool install-name-tool


【解决方案1】:

这不是一个完整的解决方案,但如果您只想在构建其他内容时包含您构建的一些本地库,您可以创建 ~/lib~/include 文件夹并将文件放在那里。这些文件夹位于默认路径上。

https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/UsingDynamicLibraries.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-09
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-31
    相关资源
    最近更新 更多