dyld: Library not loaded: /opt/local/lib/libglib-2

2019-09-05 08:02发布

问题:

I've gotten MDB-Tools compiled for OSX, but when I try to run a sample command line program on another computer I get this error:

dyld: Library not loaded: /opt/local/lib/libglib-2.0.0.dylib Referenced from: /Users/dev/mdb/mdb-test Reason: image not found Trace/BPT trap: 5

I believe that this means that the target system is missing a library and I think its something to do with linkage, but I'm not exactly positive how to go about fixing this. Could anyone point me in the right direction?

回答1:

The /opt/local directory is typically used by MacPorts. Your compiled program has a dependency on glib from MacPorts. You either need to install that on the machines where you want to run your program or you need to bundle together your program and all of the libraries it depends on.

Check Apple's Dynamic Library Programming Topics.



回答2:

Yes, I had hit similar issue while upgrading vim on Mac.

$ vi linkedlist.cc
dyld: Library not loaded: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.6/Python
  Referenced from: /usr/local/bin/vim
  Reason: image not found
Abort trap: 6

To solve the problem, I tried to upgrade packages.

$ brew update
Already up-to-date.

$ brew upgrade

It started working after doing upgrades.