Library not loaded: @rpath/

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.24.06
Platform: macOS Monterey 12.2.1

I have an executable that can run without any issues at the command line like follow:

./example arg1 arg2 arg3

where arg1-3 are just some command-line arguments.

However, if I put the same line into a bash script:


./example arg1 arg2 arg3

I get the following error:

dyld[32773]: Library not loaded: @rpath/
  Referenced from: /<path_to_executable>/example
  Reason: tried: '/usr/local/lib/' (no such file), '/usr/lib/' (no such file)

In my makefile, I have the following:

ROOTCFLAGS= `root-config --cflags`
ROOTGLIBS=`root-config --glibs`

where ROOTGLIBS holds the correct path to the file, which is different from the paths listed in the error.

@Axel This seems to be macOS specific.

Hi @Pete,

This may run on the command line because libraries might be found on the search path via DYLD_LIBRARY_PATH instead of the rpath specified in the binary.

Therefore, you need to make sure that the linker sets the rpath for the generated binary. If that’s the case, the following command

$ root-config --glibs

should include something similar to -Wl,-rpath,/path/to/root/build/lib as part of the output. Could you check that?


Hi @jalopezg, I have the following:

>root-config --glibs
>-L/Users/myhome/cern_root/root-6.24.06/installdir/lib -lGui -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -stdlib=libc++ -lpthread -lm -ldl


Indeed, it seems that the rpath is not specified. Do you see the same for root-config --libs? @Axel any hint here?


Hi @jalopezg,

I get the same output for root-config --libs.

In case you get no further help here … in the beginning of your shell script, try to add:
source $(root-config --bindir)/

Hi @Wile_E_Coyote,

Adding in that line to the shell script fixes my issue. I don’t get the error anymore. Thank you!