Search code examples
c++macosrpathbazel

How do I set the rpath for C++ with Bazel on OS X


I have tried adding the following to my BUILD file:

linkopts = ["-Wl,-rpath path/to/add"],

But when I check the executable with

otool -L path/to/executable

It does not include path/to/add. How can I change the rpath in the executable using bazel.


Solution

  • The issue is that -Wl,-rpath is not really supported on OS X, we have to wrap the clang compiler with a shell script that does the conversion. This shell script find the rpath specification and replace it with a call to install_name_tool.

    I haven't found a way to handle multiple rpath so far for Mach-O binaries.