# DL\_LOAD\_PATH cleared outside of module

**URL:** <https://discourse.julialang.org/t/dl-load-path-cleared-outside-of-module/32769>\
**Category:** New to Julia\
**Created:** [December 28, 2019, 8:14pm UTC](https://discourse.julialang.org/t/dl-load-path-cleared-outside-of-module/32769 "2019-12-28T20:14:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmillard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmillard/32/9448_2.png) [@dmillard](https://discourse.julialang.org/u/dmillard)\
**Post date:** [December 28, 2019, 8:14pm UTC](https://discourse.julialang.org/t/dl-load-path-cleared-outside-of-module/32769/1 "2019-12-28T20:14:54Z")

</div>

I am writing a module `Foo`, which depends on `ccall`ing some code in another part of my source tree. In my module, I `push!(Libdl.DL_LOAD_PATH, "path/to/file")`, and I’m able to find the `.so` according to some debugging.

However, outside of the module, after `using Foo`, `Libdl.DL_LOAD_PATH` is empty, and during compilation, the functions inside of `Foo` can’t find the requisite `.so`. Without the using/module barrier, everything seems okay (running lines from the REPL).

I can also successfully load the library if, after `using Foo`, I `push!` the right path again.

What’s going on? How can I fix this? An MWE seems hard to provide because it requires setting up a dev package and I’m not too familiar with the packaging system, but I can try.

---

<div class="post-metadata">

**Author:** ![Non-Contradiction](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-contradiction/32/2208_2.png) [@Non-Contradiction](https://discourse.julialang.org/u/Non-Contradiction)\
**Post date:** [December 28, 2019, 9:13pm UTC](https://discourse.julialang.org/t/dl-load-path-cleared-outside-of-module/32769/2 "2019-12-28T21:13:38Z")

</div>

Maybe you can define ` __init__ ` function for your module to `push!` the path and execute any other initialization steps at the runtime. Search ` __init__ ` on [https://docs.julialang.org/en/v1/manual/modules/#](https://docs.julialang.org/en/v1/manual/modules/#) to see explanations and examples.

---

<div class="post-metadata">

**Author:** ![dmillard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmillard/32/9448_2.png) [@dmillard](https://discourse.julialang.org/u/dmillard)\
**Post date:** [December 29, 2019, 6:04pm UTC](https://discourse.julialang.org/t/dl-load-path-cleared-outside-of-module/32769/3 "2019-12-29T18:04:11Z")

</div>

This solved my problem perfectly. Thanks so much for the pointer! I suppose I was confused about the difference between what happens at compile time and what happens at runtime, and this clarified the split perfectly.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [December 31, 2019, 12:38pm UTC](https://discourse.julialang.org/t/dl-load-path-cleared-outside-of-module/32769/4 "2019-12-31T12:38:26Z")

</div>

> [@dmillard](#):
>
> I am writing a module `Foo` , which depends on `ccall` ing some code in another part of my source tree. In my module, I `push!(Libdl.DL_LOAD_PATH, "path/to/file")` , and I’m able to find the `.so` according to some debugging.

Don’t fiddle with `LD_LOAD_PATH`. Use a full path in `ccall` instead.

```julia
const my_library = joinpath(@ __DIR__ , "relative/path/to/somewhere/else/in/my/source/tree/library.so")
function my_wrapper(...)
    ccall((:my_function, my_library), ...)
end

```
