Error “Library not loaded” when launching app

2019-03-14 02:12发布

I have created a Mac app which uses the RMSharedPreferences framework. When opening the app, it immediately crashes and I get the following error:

Dyld Error Message:
  Library not loaded: @rpath/RMSharedPreferences.framework/Versions/A/RMSharedPreferences
  Referenced from: /Users/USER/Desktop/MyApp.app/Contents/MacOS/MyApp
  Reason: image not found

It seems that it can't find the framework. I have tried adding a copy files phase to the target which should copy the framework and when browsing the contents of the app in Finder, it seems that it is copied correctly.

Does anyone know what might cause this error?

EDIT: Setting the framework to optional does make the application launch without any errors but the application does not fully work. Any RMSharedPreferences related calls will be ignored.

Copy framework. Contents of app.

2条回答
forever°为你锁心
2楼-- · 2019-03-14 02:27

@rpath is a more flexible keyword, and its use is recommended.

The better way to do this is to set the "Runpath Search Paths" build setting in Xcode.

This avoids the need for an additional build phase script to modify the framework.

For instance, in your situation, you could set "Runpath Search Paths" to

@executable_path/../Frameworks

or

@loader_path/../Frameworks

if you're trying to load the framework from within a framework.

查看更多
Viruses.
3楼-- · 2019-03-14 02:30

Since you are bundling the framework with your app, you should set the framework's install location. You can set that in your framework target build setting "installation location". Use something like:

@executable_path

You could also use a separate folder for your frameworks, then you would use:

@executable_path/../Frameworks/

In case you can't rebuild the framework (which is not yours, but I am saying in general), you can modify a prebuilt framework installation path like this:

install_name_tool -id @executable_path/../Frameworks/<framework_name> <your_framework>

Here you can find a reference for this.

If you are going to bundle a framework inside another framework, you can use @loader_path instead of @executable_path.

查看更多
登录 后发表回答