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:
#!/bin/bash
./example arg1 arg2 arg3
I get the following error:
dyld[32773]: Library not loaded: @rpath/libGui.so
Referenced from: /<path_to_executable>/example
Reason: tried: '/usr/local/lib/libGui.so' (no such file), '/usr/lib/libGui.so' (no such file)
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?