Ok I realize that dlopen may not be a new-to-Julia issue, but FFI is important for us to be able to expand usage of Julia in my company. I have read through the manual section on using C and Fortran (which is rather good, actually). I think what I am running into here is likely a filesystem path problem.
After compiling it as indicated in the comments of the code, I change to the directory that the shared library is in, and start Julia:
julia> @ccall "./libmyexp".my_exp(3.0::Float64)::Float64
20.085536923187668
julia> using Libdl
julia> h = dlopen("./libmyexp")
Ptr{Nothing} @0x000000000152a330
julia> h = dlopen("./libmyexp.so")
Ptr{Nothing} @0x000000000152a330
Am I missing a path or something? Also, is it the “Julian way” to use dlopen and dlsym when the @ccall macro seems to be how you end up calling it anyhow?
Oh, perhaps I should have also put this, niether of the dlsym handles seems to work:
julia> @ccall h.my_exp(3.0::Float64)::Float64
ERROR: TypeError: in ccall, expected Symbol, got a value of type Ptr{Nothing}
Stacktrace:
[1] top-level scope
@ ./REPL[5]:1
@Sukera, ok thanks, that can work - just calling it like that.
I guess I had been used to using dlopen and dlsym in other FFI cases in Python …
I also tried to make the handle with an absolute path, and that didn’t work either:
julia> h = dlopen("/home/me/Projects/Julia/libmyexp.so")
Ptr{Nothing} @0x000000000152a330
julia> ccall(("my_exp", h), Float64, (Float64,), 3.0)
ERROR: TypeError: in ccall, expected Symbol, got a value of type Ptr{Nothing}
Stacktrace:
[1] top-level scope
@ ./REPL[11]:1
(deleted something that I found out wasn’t valid)