FFTW.jl : could not load library "libfftw3"

I am facing this issue, I have provided the information that has been used to solve this issue. https://github.com/JuliaMath/FFTW.jl/issues/110
It’s local issue to my system and works fine for another contributor there.

(@v1.6) pkg> activate .
  Activating environment at `~/julia-related/MusicProcessing.jl/Project.toml`

julia> using Revise

julia> using MusicProcessing

julia> using FFTW

julia> pathof(FFTW)
"/home/ashwani/.julia/packages/FFTW/Iu2GG/src/FFTW.jl"

julia> FFTW.libfftw3
"/home/ashwani/.julia/artifacts/81791030d1dcd08bf0c67b3e8224cb573d0f5a0a/lib/libfftw3.so"

julia> FFTW.libfftw3f
"/home/ashwani/.julia/artifacts/81791030d1dcd08bf0c67b3e8224cb573d0f5a0a/lib/libfftw3f.so"

julia> using Libdl

julia> Libdl.dlsym(Libdl.dlopen(FFTW.libfftw3), :fftw_threads_set_callback)
Ptr{Nothing} @0x00007fb0086c2c40

julia> using SHA

julia> bytes2hex(open(FFTW.libfftw3) do f; sha2_256(f); end)
"39042b7f2893eec46e184d358125be75eb196045b844421b2e9f7a90d80b25fa"

julia> bytes2hex(open(FFTW.libfftw3f) do f; sha2_256(f); end)
"da8463cf4325e73178e97fcd69b62f31707132aed390650ca8679881a6637de2"

# this is where issue is in my system
julia> Libdl.dlsym(Libdl.dlopen(FFTW.libfftw3f), :fftw_threads_set_callback)
ERROR: could not load symbol "fftw_threads_set_callback":
/home/ashwani/.julia/artifacts/81791030d1dcd08bf0c67b3e8224cb573d0f5a0a/lib/libfftw3f.so: undefined symbol: fftw_threads_set_callback

julia> audio_one_channel = SampleBuf(rand(1000), 10)
1000-element SampleBuf{Float64, 1}:
 0.7188992365329432
 0.9291267382769475
 0.9235711252208105
 0.7298652018343716
 ⋮
 0.7817233868027189
 0.9691375556064439
 0.009171005643992869

julia> speedup(audio_one_channel, 1.5)
# also this doesn't make much sense yet to me
ERROR: could not load library "libfftw3"
libfftw3.so: cannot open shared object file: No such file or directory
Stacktrace:
 [1] plan_dft_c2r_1d!
   @ ~/julia-related/MusicProcessing.jl/src/complex.jl:22 [inlined]
 [2] irfft!(dest::Vector{Float64}, src::Ptr{ComplexF64}, nfft::Int64)
   @ MusicProcessing ~/julia-related/MusicProcessing.jl/src/complex.jl:35
 [3] istft(stft::Matrix{ComplexF64}, samplerate::Float64, windowsize::Int64, hopsize::Int64; nfft::Int64, window::typeof(DSP.Windows.hanning))
   @ MusicProcessing ~/julia-related/MusicProcessing.jl/src/TFR.jl:117
 [4] istft
   @ ~/julia-related/MusicProcessing.jl/src/TFR.jl:101 [inlined]
 [5] #speedup#3
   @ ~/julia-related/MusicProcessing.jl/src/audio.jl:99 [inlined]
 [6] speedup (repeats 3 times)
   @ ~/julia-related/MusicProcessing.jl/src/audio.jl:97 [inlined]
 [7] top-level scope
   @ REPL[15]:1

version info:

julia> versioninfo()
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

What if you replace

with

    ccall((:fftw_plan_dft_c2r_1d, libfftw3), FFTW.PlanPtr, (Cint, Ptr{Complex{Float64}}, Ptr{Float64}, Cuint), nfft, src, dest, 0)

?

When I use simply libfftw3 and this particular one is called in test, test throws this error

UndefVarError: libfftw3 not defined

and in these other functions as shown above by you in complex.jl, whenever they are called…below mentioned errors are thrown

 Test threw exception
  Expression: duration(speedup(audio_multi_channel, 2)) ≈ duration(audio_multi_channel) // 2
  could not load library "libfftw3f"
  libfftw3f.so: cannot open shared object file: No such file or directory

Did you actually import FFTW somewhere? I see it’s in the Project.toml of your package. If FFTW isn’t loaded how do you expect to be able to call into the library?

It’s there in MusicProcessing.jl file, should I import libfftw3f and libfftw3 specifically?

You can also do FFTW.libfftw3, FFTW.jl doesn’t re-export that variable.

1 Like

Grazie, using this method and specifically importing those files worked for me:

import FFTW.libfftw3, FFTW.libfftw3f
.
.
function plan_dft_c2r_1d!(dest::ArrayLike{Float32}, src::ArrayLike{Complex{Float32}}, nfft::Int)
    ccall((:fftwf_plan_dft_c2r_1d, libfftw3f), FFTW.PlanPtr, (Cint, Ptr{Complex{Float32}}, Ptr{Float32}, Cuint), nfft, src, dest, 0)
end

function plan_dft_c2r_1d!(dest::ArrayLike{Float64}, src::ArrayLike{Complex{Float64}}, nfft::Int)
    ccall((:fftw_plan_dft_c2r_1d, libfftw3), FFTW.PlanPtr, (Cint, Ptr{Complex{Float64}}, Ptr{Float64}, Cuint), nfft, src, dest, 0)
end