iSpark
iSpark

Reputation: 952

Load custom dynamic library(.dylib) in iOS application

I have created one custom library called 'Library.dylib',now I am trying to add that dylib file in another iOS project and it is giving following error,

dyld: Library not loaded: @executable_path/Library.dylib Referenced from: /Users/xxxx/Library/Developer/CoreSimulator/Devices/4CCFE5F7-494B-41DE-AEB9-5040418518B4/data/Containers/Bundle/Application/A97A1947-80B5-9AA0-B46F-C11E25A94553/DyLibTest.app/DyLibTest Reason: image not found

In Mac app if we copy it in /usr/lib/ path it is working, but not in iOS app.

Please let me know how to use custom dylib in iOS application?

FYI I want to use only dynamic linking not static linking(.a)

enter image description here

enter image description here

Upvotes: 0

Views: 8356

Answers (2)

Anonimys
Anonimys

Reputation: 696

You must put *.dylib file in Embed Libraries.

Project -> Build Phases -> Embed Libraries

Click to "+" and choose your *.dylib file.

Upvotes: 0

Jens Meder
Jens Meder

Reputation: 4367

As far as I can see your app expects your library to be copied to @executable_path/Library.dylib. Yet, if you add your library to the Embed Frameworks build phase (which I assume you did) it will be copied to the Frameworks subfolder in your app bundle and therefore cannot be loaded by your app.

There are two solutions:

1) Change the destination of the Embed Frameworks build phase from Frameworks to Executables. In general, I wouldn't recommend to change that though.

2) Adjust the Runpath Search Paths in your build settings to include @executable_path/Frameworks.

Hope that helps.

Upvotes: 3

Related Questions