# Libdl.dlopen usage change since v0.7?

**URL:** <https://discourse.julialang.org/t/libdl-dlopen-usage-change-since-v0-7/22625>\
**Category:** General Usage\
**Tags:** ccall\
**Created:** [April 2, 2019, 2:07am UTC](https://discourse.julialang.org/t/libdl-dlopen-usage-change-since-v0-7/22625 "2019-04-02T02:07:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vonDonnerstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vondonnerstein/32/7756_2.png) [@vonDonnerstein](https://discourse.julialang.org/u/vonDonnerstein)\
**Post date:** [April 2, 2019, 2:07am UTC](https://discourse.julialang.org/t/libdl-dlopen-usage-change-since-v0-7/22625/1 "2019-04-02T02:07:56Z")

</div>

I was trying to convert my codebase from 0.6 to 1.x, but noticed that all pointers from Libdl within a module now appear nulled after compilation. With the following module:

```julia
module MyModule
  lib = Libdl.dlopen("/path/to/my/lib.so")
  function foo()
    println(lib)
  end
end

```

typing the following into the REPL:

```julia
using MyModule
MyModule.foo()

```

yields

Ptr{Void} @0x000000000424bc60  
in v0.6

but

Ptr{Nothing} @0x0000000000000000  
in v0.7 and beyond

What I’m trying to achieve in my module is to open a library once, call it’s very expensive initialization once and then define a jl-function that can be called many times. But since the handle opened outside the function is nulled inside the function since 0.7, I now seemingly have to dlopen and initialize inside the function, i.e. have the expensive initialization in every function call. How can I avoid this? (The printing of the handle here is just a placeholder for any ccall I might want to make on that handle)

Btw, I’ve noticed that if I define the module inside the REPL and not as a package I still get the old behavior. Not sure why that changes anything.

---

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [April 2, 2019, 2:52am UTC](https://discourse.julialang.org/t/libdl-dlopen-usage-change-since-v0-7/22625/2 "2019-04-02T02:52:57Z")

</div>

You’ll need to put that type of dynamic initialization inside your module’s ` __init__ ` function. See [these docs](https://docs.julialang.org/en/v1/manual/modules/index.html#Module-initialization-and-precompilation-1) for details.

---

<div class="post-metadata">

**Author:** ![vonDonnerstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vondonnerstein/32/7756_2.png) [@vonDonnerstein](https://discourse.julialang.org/u/vonDonnerstein)\
**Post date:** [April 3, 2019, 6:18pm UTC](https://discourse.julialang.org/t/libdl-dlopen-usage-change-since-v0-7/22625/3 "2019-04-03T18:18:54Z")

</div>

Thank you! That’s it, and the code just worked in v0.6 because precompilation is only switched on by default since v0.7.
