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