Libdl.dlopen or Libdl.find_library does not find a shared library

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> 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?

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.

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

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

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

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

?

> 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.

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().

3 Likes

I’ll try that, thanks!

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

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

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

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

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.

1 Like