# Libdl.dlopen or Libdl.find\_library does not find a shared library

**URL:** <https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161>\
**Category:** General Usage\
**Tags:** question, error\
**Created:** [February 12, 2021, 5:07pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161 "2021-02-12T17:07:12Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/siel/32/21932_2.png) [@Siel](https://discourse.julialang.org/u/Siel)\
**Post date:** [February 12, 2021, 5:07pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/1 "2021-02-12T17:07:12Z")

</div>

I’m trying to call a custom C library whitin Julia but everything I tried have been fruiteless. I always get exactly the same error: `/home/siel/Dev/npodjl/ipm_v2.so: cannot open shared object file: No such file or directory`.

```julia
julia> using Libdl

julia> pwd()
"/home/siel/Dev/npodjl"

julia> readdir()
8-element Array{String,1}:
 ".git"
 ".vscode"
 "Manifest.toml"
 "Project.toml"
 "ipm_v2.so"
 "libs"
 "src"
 "test"

julia> Libdl.find_library("imp_v2.so", [pwd()])
""

julia> Libdl.find_library("imp_v2.so", ["/home/siel/Dev/npodjl"])
""

julia> Libdl.dlopen("ipm_v2.so")
ERROR: could not load library "ipm_v2.so"
/home/siel/Dev/npodjl/ipm_v2.so: cannot open shared object file: No such file or directory
Stacktrace:
 [1] dlopen(::String, ::UInt32; throw_error::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109
 [2] dlopen at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109 [inlined] (repeats 2 times)
 [3] top-level scope at REPL[13]:1

julia> Libdl.dlopen("/home/siel/Dev/npodjl/imp_v2.so")
ERROR: could not load library "/home/siel/Dev/npodjl/imp_v2.so"
/home/siel/Dev/npodjl/imp_v2.so: cannot open shared object file: No such file or directory
Stacktrace:
 [1] dlopen(::String, ::UInt32; throw_error::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109
 [2] dlopen at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109 [inlined] (repeats 2 times)
 [3] top-level scope at REPL[14]:1

julia> ccall((:c_emint, "/home/siel/Dev/npodjl/imp_v2.so"), Cvoid, (Int32,), 64)
ERROR: could not load library "/home/siel/Dev/npodjl/imp_v2.so"
/home/siel/Dev/npodjl/imp_v2.so: cannot open shared object file: No such file or directory
Stacktrace:
 [1] top-level scope at ./REPL[15]:1

```

Any suggestions?

---

<div class="post-metadata">

**Author:** ![bcmichael](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bcmichael/32/10003_2.png) [@bcmichael](https://discourse.julialang.org/u/bcmichael)\
**Post date:** [February 12, 2021, 5:16pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/2 "2021-02-12T17:16:39Z")

</div>

I think you spelled the filename wrong. It looks like it is named ipm\_v2.so, but you keep trying to open imp\_v2.so.

---

<div class="post-metadata">

**Author:** ![Siel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/siel/32/21932_2.png) [@Siel](https://discourse.julialang.org/u/Siel)\
**Post date:** [February 12, 2021, 5:21pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/3 "2021-02-12T17:21:42Z")

</div>

Yes I have some misspells but the error is still there:

```julia
julia> Libdl.dlopen("ipm_v2.so")
ERROR: could not load library "ipm_v2.so"
/home/siel/Dev/npodjl/ipm_v2.so: cannot open shared object file: No such file or directory
Stacktrace:
 [1] dlopen(::String, ::UInt32; throw_error::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109
 [2] dlopen at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109 [inlined] (repeats 2 times)
 [3] top-level scope at REPL[17]:1

julia> Libdl.dlopen("/home/siel/Dev/npodjl/ipm_v2.so")
ERROR: could not load library "/home/siel/Dev/npodjl/ipm_v2.so"
/home/siel/Dev/npodjl/ipm_v2.so: cannot open shared object file: No such file or directory
Stacktrace:
 [1] dlopen(::String, ::UInt32; throw_error::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109
 [2] dlopen at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109 [inlined] (repeats 2 times)
 [3] top-level scope at REPL[18]:1

julia> ccall((:c_emint, "/home/siel/Dev/npodjl/ipm_v2.so"), Cvoid, (Int32,), 64)
ERROR: could not load library "/home/siel/Dev/npodjl/ipm_v2.so"
/home/siel/Dev/npodjl/ipm_v2.so: cannot open shared object file: No such file or directory
Stacktrace:
 [1] top-level scope at ./REPL[19]:1

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [February 12, 2021, 5:54pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/4 "2021-02-12T17:54:28Z")

</div>

Does the library link to other libraries? What’s the output of the shell command

```julia
ldd /home/siel/Dev/npodjl/ipm_v2.so

```

?

---

<div class="post-metadata">

**Author:** ![Siel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/siel/32/21932_2.png) [@Siel](https://discourse.julialang.org/u/Siel)\
**Post date:** [February 12, 2021, 6:09pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/5 "2021-02-12T18:09:00Z")

</div>

```julia
> ldd ipm_v2.so
        linux-vdso.so.1 (0x0000007fa31fc000)
        /usr/lib/aarch64-linux-gnu/libgomp.so.1 (0x0000007f9d332000)
        libR.so => /usr/lib/libR.so (0x0000007f9cf1a000)
        libgfortran.so.4 => /usr/lib/aarch64-linux-gnu/libgfortran.so.4 (0x0000007f9ce17000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007f9ccbe000)
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007f9cc92000)
        /lib/ld-linux-aarch64.so.1 (0x0000007fa31d0000)
        libblas.so.3 => /usr/lib/aarch64-linux-gnu/libblas.so.3 (0x0000007f9cc26000)
        libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007f9cb6d000)
        libreadline.so.7 => /lib/aarch64-linux-gnu/libreadline.so.7 (0x0000007f9cb17000)
        libpcre.so.3 => /lib/aarch64-linux-gnu/libpcre.so.3 (0x0000007f9caa5000)
        liblzma.so.5 => /lib/aarch64-linux-gnu/liblzma.so.5 (0x0000007f9ca75000)
        libbz2.so.1.0 => /lib/aarch64-linux-gnu/libbz2.so.1.0 (0x0000007f9ca55000)
        libz.so.1 => /lib/aarch64-linux-gnu/libz.so.1 (0x0000007f9ca28000)
        libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000007f9ca13000)
        libicuuc.so.60 => /usr/lib/aarch64-linux-gnu/libicuuc.so.60 (0x0000007f9c83f000)
        libicui18n.so.60 => /usr/lib/aarch64-linux-gnu/libicui18n.so.60 (0x0000007f9c581000)
        libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000007f9c55d000)
        libopenblas.so.0 => /usr/lib/aarch64-linux-gnu/libopenblas.so.0 (0x0000007f9be95000)
        libtinfo.so.5 => /lib/aarch64-linux-gnu/libtinfo.so.5 (0x0000007f9be5d000)
        libicudata.so.60 => /usr/lib/aarch64-linux-gnu/libicudata.so.60 (0x0000007f9a4a4000)
        libstdc++.so.6 => /usr/lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000007f9a310000)

```

Yes, I’m using some fortran and some C there.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [February 12, 2021, 6:22pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/6 "2021-02-12T18:22:11Z")

</div>

Note that the “No such file or directory” error is often misleading: it’s totally possible that it’s one of the files needed by `/home/siel/Dev/npodjl/ipm_v2.so` that can’t be found, not that file itself. You can see what’s the missing file if you use `strace`. Generally speaking, you need to dlopen all libraries which aren’t dlopened yet. You can see the list of open libraries in Julia with `Libdl.dllist()`.

---

<div class="post-metadata">

**Author:** ![Siel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/siel/32/21932_2.png) [@Siel](https://discourse.julialang.org/u/Siel)\
**Post date:** [February 12, 2021, 9:09pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/7 "2021-02-12T21:09:11Z")

</div>

I’ll try that, thanks!

---

<div class="post-metadata">

**Author:** ![Siel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/siel/32/21932_2.png) [@Siel](https://discourse.julialang.org/u/Siel)\
**Post date:** [February 12, 2021, 9:25pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/8 "2021-02-12T21:25:56Z")

</div>

Thanks @giordano, you were right!  
Somehow that error message should change to something more informative though.

```julia
julia> Libdl.dlopen("/home/siel/Dev/npodjl/libs/ipm.so")
Ptr{Nothing} @0x0000000002025290

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [February 12, 2021, 9:38pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/9 "2021-02-12T21:38:55Z")

</div>

> [@Siel](#):
>
> Somehow that error message should change to something more informative though

That’s an error message from the kernel, not Julia 🙂

---

<div class="post-metadata">

**Author:** ![helgee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgee/32/2022_2.png) [@helgee](https://discourse.julialang.org/u/helgee)\
**Post date:** [April 29, 2021, 3:37pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/10 "2021-04-29T15:37:47Z")

</div>

> [@giordano](#):
>
> You can see what’s the missing file if you use `strace` .

Care to elaborate on that? Which syscalls do I need to trace? 😉

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [April 29, 2021, 3:44pm UTC](https://discourse.julialang.org/t/libdl-dlopen-or-libdl-find-library-does-not-find-a-shared-library/55161/11 "2021-04-29T15:44:57Z")

</div>

I usually run `strace` without filtering the output and in the log search for the error message “No such file or directory”, trying to understand what it’s actually referring to. An option could be to only filter opening of files, but it really depends on what’s failing exactly.
