# FFTW.jl : could not load library "libfftw3"

**URL:** https://discourse.julialang.org/t/fftw-jl-could-not-load-library-libfftw3/60995
**Category:** General Usage
**Created:** [May 12, 2021, 3:43am UTC](https://discourse.julialang.org/t/fftw-jl-could-not-load-library-libfftw3/60995 "2021-05-12T03:43:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)
#### Post date: [May 12, 2021, 3:43am UTC](https://discourse.julialang.org/t/fftw-jl-could-not-load-library-libfftw3/60995/1 "2021-05-12T03:43:00Z")

</div>

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](https://github.com/JuliaMath/FFTW.jl/issues/110)  
It’s local issue to my system and works fine for another contributor there.

```julia
(@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
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)

```

---

<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: [May 17, 2021, 11:41am UTC](https://discourse.julialang.org/t/fftw-jl-could-not-load-library-libfftw3/60995/2 "2021-05-17T11:41:25Z")

</div>

What if you replace

> <https://github.com/JuliaMusic/MusicProcessing.jl/blob/2867bf1625d750d39952a7ece9f0c806f8a08a1d/src/complex.jl#L22>

with

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

```

?

---

<div class="post-metadata">

### Author: ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)
#### Post date: [May 17, 2021, 12:00pm UTC](https://discourse.julialang.org/t/fftw-jl-could-not-load-library-libfftw3/60995/3 "2021-05-17T12:00:34Z")

</div>

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

```julia
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

```julia
 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

```

---

<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: [May 17, 2021, 12:03pm UTC](https://discourse.julialang.org/t/fftw-jl-could-not-load-library-libfftw3/60995/4 "2021-05-17T12:03:12Z")

</div>

> [@Ashwani\_Rathee](#):
>
> When I use simply libfftw3 and this particular one is called in test, test throws this error

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?

---

<div class="post-metadata">

### Author: ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)
#### Post date: [May 17, 2021, 12:07pm UTC](https://discourse.julialang.org/t/fftw-jl-could-not-load-library-libfftw3/60995/5 "2021-05-17T12:07:43Z")

</div>

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

---

<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: [May 17, 2021, 12:18pm UTC](https://discourse.julialang.org/t/fftw-jl-could-not-load-library-libfftw3/60995/6 "2021-05-17T12:18:02Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)
#### Post date: [May 17, 2021, 12:28pm UTC](https://discourse.julialang.org/t/fftw-jl-could-not-load-library-libfftw3/60995/7 "2021-05-17T12:28:25Z")

</div>

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

```julia
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

```
