简体   繁体   中英

Xcode can run my program, but I can't run it manually

I have a project with a dynamic library and an executable that links against it. I can successfully start it with Xcode, but when I try to run it from the command line, dyld complains about the library not being in the install path:

$ /Users/USER/Library/Developer/Xcode/DerivedData/PROJECT/Build/Products/Debug/EXECUTABLE 
dyld: Library not loaded: /usr/local/lib/libMyLib.dylib
  Referenced from: /Users/USER/Library/Developer/Xcode/DerivedData/PROJECT/Build/Products/Debug/EXECUTABLE 
  Reason: image not found
Trace/BPT trap: 5

The problem is quite clear: the library isn't in its advertised install path. However, I don't really want to deploy it there, and besides, Xcode still manages to start my program.

How can I run my program without installing the library in /usr/local/lib ?

If you're relying on a dylib, then it needs to be installed in the appropriate location.

Using a framework might help, as you can package it in your application, using @executable_path ...
But then, of course, you won't be able to share it across different applications.

So basically, you need to tell Xcode to install your dynamic library.
This can be done in your build settings, in the Deployment section.

Mainly, Deployment location , Installation directory , Skip install , etc...

Note that you can also do this for frameworks, installing them into /Library/Frameworks/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM