I’d like to specify a relative path in my code. My code is to be compiled by
PackageCompiler and be used by many others, so it must be relocatable. There are mainly two points:
- it should behave the same wherever it is runned. That is to say, the path should be relative to where the binary exists, instead of where the binary is executed.
- it should run in different machines, as long as I copy all files needed.
It seems that
@path macro from
RelocatableFolders.jl suffices, but are there better ways? Like utilizing
But after simple test, I found
ENV["DT_RPATH"] will not be the real
RPATH for compiled binaries.
MWE, a simple package:
module SelfTest function test_rpath() println(ENV["DT_RPATH"]) end function julia_main()::Cint test_rpath() return 0 end end
Compile it and run:
$ ./bin/bin/SelfTest hwloc/linux: Ignoring PCI device with non-16bit domain. Pass --enable-32bits-pci-domain to configure to support such devices (warning: it would break the library ABI, don't enable unless really needed). /public/opt/tools/julia/julia-1.9.0/lib/julia:/public/opt/tools/julia/julia-1.9.0/lib $ chrpath -l ./bin/bin/SelfTest ./bin/bin/SelfTest: RPATH=$ORIGIN/../lib:$ORIGIN/../lib/julia