dyld: Library not loaded: ../lib/abc.dynlib

ぃ、小莉子 提交于 2019-12-12 23:42:16

问题


I am having trouble getting a my XCode 4.2 project to run against a dynamic library (dynlib).

What I am doing is adding the library into xcode project, and then creating a new 'Copy Files' build phase with this lib.

The project does(!) run well if I set the Destination in the build phase to 'Products Directory', but then I have to deliver the lib with the app as opposed to embedded inside it.

I get the error in the title in all other settings of Destination in the build phase.

Also, I tried to quit xcode, delete build directory, clean, and all such tricks.

Is there a project/target setting I am missing? Why is XCode looking for the dynlib in '../lib/'? (as shown in error)


回答1:


You have two options a) change the library ID, b) change the final product.

The ID is embedded in the dylib and it defines where dyld will look for it. The ID is taken from the library at link time (when no other special flags are used). You can check it with otool -L, e.g.:

gammu:~$ otool -L /usr/lib/libz.dylib 
/usr/lib/libz.dylib:
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)

The first line is the ID of the dylib. You can change it using install_name_tool -id <path> <library>. One option you have is to use the special form @executable_path/... which looks starting from the location of your binary (there are others as well).

The second option (achieving the same thing) is to change the path to the library in your product. You can check how it links libraries with the same otool -L command:

gammu:~$ otool -L /usr/bin/emacs
/usr/bin/emacs:
    /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)

You can then change the libraries with install_name_tool -change <old> <new> <target>, e.g.:

install_name_tool -change ../lib/abc.dynlib @executable_path/../lib/abc.dylib foo

Finally, note that Xcode usually does all this for you automatically if you let it manage the dylib (instead of copying it manually).




回答2:


I have same problem and tried the first solution, first option doesn't work. Second option alone can't solve the issue.

Instead in Xode Build settings of dylib set "Dynamic Library Install Name" to "<newpath>/<your.dylib>". Newpath is the path where your object file foo can look and the it is the same path you will keep the your dylib. After your build dylib and use it for building your object file, these path will automatically put in to the object file .

You may confirm with otool -L for both objective file and dylib.




回答3:


I had the same problem and solved with this way:

Find the missing file:

mdfind libz.1.dylib

It was here: /Applications/Vagrant/embedded/lib/libz.1.dylib

Copy it to missing folder with super user rights:

sudo sudo cp /Applications/Vagrant/embedded/lib/libz.1.dylib /usr/lib/libz.1.dylib

Done, everything works as usual.



来源:https://stackoverflow.com/questions/8654651/dyld-library-not-loaded-lib-abc-dynlib

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