0

I have created a dylib file. Successfully added it to one Terminal(Console based app through Xcode). When I run the app through Xcode they dylib is loaded and all the methods inside it works.

The issue is when I run the Consols App (Unix Executable) it fails to find the dylib and throws the following error.

DS-Anoopkumar-v:~ anoopvaidya$ /Users/anoopvaidya/Library/Developer/Xcode/DerivedData/Worker-dfytfqadwmzqmvesrzqeartqcggx/Build/Products/Debug/Worker; exit; dyld: Library not loaded: @executable_path/../libDownloader.dyli
Referenced from: /Users/anoopvaidya/Library/Developer/Xcode/DerivedData/Worker-dfytfqadwmzqmvesrzqeartqcggx/Build/Products/Debug/Worker
Reason: image not found Trace/BPT trap: 5 logout

[Process completed]

Please tell me what I am missing here, any help will be highly appreciated.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140

1 Answers1

0

In Build Setting's "Dynamic Library Install Name" I replaced "@executable_path/.../Framework/libILDownloader.dylib" with "@executable_path/libILDownloader.dylib" and it worked.

enter image description here

Thanks to this answer How to use dylib in Mac OS X (C++), that helped me to understand

Community
  • 1
  • 1
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • That's not the whole story though is it. Firstly you must have a script that is copying `libILDownloader.dylib` to the same folder as the executable, as by default each Xcode target builds into a separate folder. Secondly when it comes to release/install, the `.dylib` probably wants to live in `/usr/local/lib`, so you should use different settings for Debug and Release builds. It's unusual (and fiddly) to have a command line executable that requires a 3rd-party `.dylib` to be installed in order to work, so you are probably better off statically linking in this library. – trojanfoe Apr 20 '15 at 14:34