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

后端 未结 1 1362
星月不相逢
星月不相逢 2020-12-17 06:32

All:

I have successfully set up two projects (Hello and World) in one workspace (HelloWorld). These are simple projects that are supposed to work together as a main

相关标签:
1条回答
  • 2020-12-17 07:08
    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

    0 讨论(0)
提交回复
热议问题