Build dynamic libraries for IOS and load them at runtime

Source: Internet
Author: User

Compiled Libmt.dylib, and test program calls, are normal. The problem occurs when the call is normal in Xcode and the implicit call is present.

Tips

Dyld:library not loaded.

Even the presence of/usr/lib/limt.dylib also reported errors. Suspect that the app is not searching for this dylib when it runs.

In the Mac platform environment, the dynamic Library (dylib) has an "install name", which is a path that exists in the dynamic library, indicating where the runtime is going to find the library. When the dynamic library is connected, the path is stored in a binary file, so the program can follow this path to find the dynamic library, otherwise it cannot load the dynamic library.

Normal can invoke the dynamic library, through the Otool tool to view the install name.

Mac-mini:bin root# Otool-L libmt.dylib libmt.dylib:/usr/lib/libmt.dylib (Compatibility version0.0.0, current version0.0.0)    /usr/lib/libsystem.b.dylib (Compatibility version1.0.0, current version1214.5.1)    /usr/lib/libz.1. Dylib (Compatibility version1.0.0, current version1.2.5)    /USR/LIB/LIBXML2.2. Dylib (Compatibility version10.0.0, current version10.9.0)

This means that the dynamic library can be found either by setting the environment variable Dyld_library_path or by placing the dynamic library in the specified location, that is, install name.

The install name can be set through the Install_name_tool tool, and the @rpath keyword can be used to specify a relative path to the installation directory by@executable_path,@loader_path关键字指定路径到运行目录。

Otool Setting the Install name

" /usr/lib/libmt.dylib " libmt.dylib

or relative path

"@rpath /lib/libmt.dylib " libmt.dylib

Reference

Http://www.chilkatforum.com/questions/4235/how-to-distribute-a-dylib-with-a-mac-os-x-application

Http://stackoverflow.com/questions/4876740/xcode-keeps-searching-dylib-at-wrong-path

Build dynamic libraries for IOS and load them at runtime

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.