ios8上怎么通过dlopen加载framework中的动态库文件
大家讲道理
大家讲道理 2017-04-17 13:43:53
0
2
245

hello.app/Frameworks/dym.framework
dlopen的第一个参数path应该怎么设置才能正确加载Frameworks/dym.framework/dym文件?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
阿神

Two projects:
dym -> dym.framework
hello -> hello.app
hello.app dynamic link dym.framework

The xcode settings for dynamic links have the following variables:
@rpath
In the hello project, the value of Run Path search paths has the following basic format:
//:configuration = Debug
LD_RUNPATH_SEARCH_PATHS = $(inherited) @loader_path/Frameworks @executable_path/Frameworks
//:configuration = Release
LD_RUNPATH_SEARCH_PATHS = $(inherited) @loader_path/Frameworks @executable_path/Frameworks

@loader_path
According to the analysis of apple doc, the directory where the binary file of the shared library is loaded is used
For example, hello.app/hello will load dym.framework/dym, then @loader_path points to the hello.app directory

@executable_path
According to the directory where the executable file in the app package is located;

The dym project needs to be set up:
Dynamic Library Install Name Base: @rpath
In this way, Dynamic Library install Name, default settings
$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)
It will be displayed as
@rpath/dym.framework/dym
Then, the corresponding install name information will be saved in the dynamic library file generated by compilation

To set up the hello project, you only need to set Run Path search paths. After compilation is completed, the path parameter information will be saved to the RPATH of the hello target file. When the program is running, it will be under the path specified by RPATH. , find the install name of the dynamic library; for how rpath is generated in the compiler, you can refer to here.

When opened with dlopen, the dynamic library will be searched according to the path specified by @rapth. It can be opened using the following format:
dlopen(“./dym.framework/dym”, RTLD_LAZY);

黄舟

Your framework should be included in the app. Then use the [NSBundle mainBundle] pathForResource series of functions to get the path.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!