Error “Library not loaded” when launching app

你离开我真会死。 提交于 2020-01-12 02:27:31

问题


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.


回答1:


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.




回答2:


@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.



来源:https://stackoverflow.com/questions/15173654/error-library-not-loaded-when-launching-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!