Search code examples
iosiphonexcode6jailbreak

How to attach library to ios project?


I'm developing a command line tool app that uses AppList library. But when i trying to run in on my device, the error occured:

dyld: Library not loaded: /usr/lib/libapplist.dylib
  Referenced from: /usr/bin/testApp
  Reason: image not found

Is it possible to attach libapplist.dylib to project package?


Solution

  • All dylibs have an installation path inside mach-o header. That path is placed in your application import section so that linker could find the dylib. When your process is launched dyld searches that path for the dylib.

    You can check that path like this:

    otool -D libapplist.dylib
    

    That's what dyld is telling you - it couldn't find the dylib. You have two options:

    1. Place your dylib where it needs to be
    2. Change installation path.

    If it's your dylib you can change it inside xcode project settings of your dylib - search for installation directory. When you rebuild dylib and application linking it they will contain the new path.

    If you can't recompile the dylib then you need to change it manually. Here is how you can do it:

    install_name_tool -id @executable_path/libapplist.dylib libapplist.dylib
    

    @executable_path tells the linker to search for dylib where application executable is located.