GrixM
GrixM

Reputation: 273

How to link a dylib with another dylib in the same directory?

I am porting a program to Mac. The program uses a dynamic library which I have compiled into a dylib using xcode. That library again uses a second library, libusb specifically. I have also compiled this into a dylib.

The two dylibs are in the same folder, the installation folder. However this does not work. It only works if I move the second libusb dylib into the /usr/local/lib folder. How can I make it so that the first library is able to link with the second library when they are both in the same folder?

I am guessing I need to edit the runpath of the first library, but I don't know what to write to make the path relative rather than absolute.

Upvotes: 1

Views: 1592

Answers (1)

christopherdrum
christopherdrum

Reputation: 1523

I believe you're looking for install_name_tool (should be in /usr/bin/install_name_tool) which assists with re-establishing dylib reference paths in macOS binaries, for exactly the problem you've described. You could run it as a build phase script to force the correct rpath of the dylib giving you trouble.

Upvotes: 1

Related Questions