Eclipse on Mac dyld: Library not loaded: Image not found

最后都变了- 提交于 2019-11-29 05:15:19
Charles Chow
dyld: Library not loaded: libWorld.dylib
Referenced from: /Users/pdl/Development/HelloWorld/Hello/Debug/Hello
Reason: image not found

This means that your program is using a dynamic library called libWorld.dylib, although you linked your dynamic library to your program during compiling. But you have to tell your program where is the dylib in run-time.

There are two solutions:

Solution 1: set up dynamic library environment variables for your project in Eclipse:

1.Right click your project name, select Run As->Run Configuration

2.Under Environment tab click New

3.Put DYLD_LIBRARY_PATH or DYLD_FALLBACK_LIBRARY_PATH in Name box

4.Put the path where your libWorld.dylib file is in Value box

For example: if libWorld.dylib file is in /opt/local/lib/my_dylib folder, than put the path in the Name box

Solution 2: set DYLD_LIBRARY_PATH in your bash configuration file

1.Normally in Mac OS, configuration file is .profile under ~/ folder, if you don't have this file than create a new file with the same name

2.Edit that file:

Add this line in your .profile file: export DYLD_LIBRARY_PATH=PATH_TO_YOUR_DYLIB:$DYLD_LIBRARY_PATH

in my example the PATH_TO_YOUR_DYLIB is opt/local/lib/my_dylib, so you just add: export DYLD_LIBRARY_PATH=/opt/local/lib/my_dylib:$DYLD_LIBRARY_PATH in .profile file

3.Problem solved, in this solution, you don't have to set up dylib path for all eclipse project

PS. DYLD_LIBRARY_PATH is an environment variable to specify the path of your dynamic library

Difference between DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH please refer to this post

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