# Best way to specify a relative path in a relocatable way?

**URL:** https://discourse.julialang.org/t/best-way-to-specify-a-relative-path-in-a-relocatable-way/102338
**Category:** General Usage
**Created:** [August 1, 2023, 2:02am UTC](https://discourse.julialang.org/t/best-way-to-specify-a-relative-path-in-a-relocatable-way/102338 "2023-08-01T02:02:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jsjie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jsjie/32/22477_2.png) [@jsjie](https://discourse.julialang.org/u/jsjie)
#### Post date: [August 1, 2023, 2:02am UTC](https://discourse.julialang.org/t/best-way-to-specify-a-relative-path-in-a-relocatable-way/102338/1 "2023-08-01T02:02:49Z")

</div>

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:

1. 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.
2. 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 `RPATH` or `RUNPATH` variable?  
But after simple test, I found `ENV["DT_RPATH"]` will not be the real `RPATH` for compiled binaries.

MWE, a simple package:

```julia
module SelfTest

function test_rpath()
    println(ENV["DT_RPATH"])
end

function julia_main()::Cint
    test_rpath()
    return 0
end

end

```

Compile it and run:

```julia
$ ./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

```

---

<div class="post-metadata">

### Author: ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)
#### Post date: [August 1, 2023, 1:08pm UTC](https://discourse.julialang.org/t/best-way-to-specify-a-relative-path-in-a-relocatable-way/102338/2 "2023-08-01T13:08:51Z")

</div>

I know that `LD_LIBRARY_PATH` is an environment variable, but I thought that `DT_RPATH` was the name of a dynamic header in an ELF file, and not an environment variable used by Linux? Thus setting `ENV["DT_RPATH"]` won’t do anything normally - perhaps PackageCompiler uses it.

I think that `RPATH` [was deprecated](https://stackoverflow.com/questions/7967848/use-rpath-but-not-runpath#:~:text=17-,But%20why%20then%20RPATH%20got%20deprecated%20in%20favor%20of%20RUNPATH,path%20even%20for%20development%20purposes.) and we were supposed to be using `RUNPATH`?

---

<div class="post-metadata">

### Author: ![jsjie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jsjie/32/22477_2.png) [@jsjie](https://discourse.julialang.org/u/jsjie)
#### Post date: [August 2, 2023, 12:40am UTC](https://discourse.julialang.org/t/best-way-to-specify-a-relative-path-in-a-relocatable-way/102338/3 "2023-08-02T00:40:14Z")

</div>

Yes, at least for new systems (old ones may not support RUNPATH). But I did not find a way to use that, too.  
My final solution is to offer an environmental variable for users to set, because in my case, the path is only used to find some configuration files.
