0

I'm currently trying to install a few Ruby Gems that require the fftw3 library to be installed and linked correctly on Windows 10. It's a one-line fix on Linux, so I'm rather annoyed at this point.

  • fftw3 ~> 0.3
  • convolver ~> 0.3.1

I have Ruby 2.2.4 (64-bit) installed and the 64-bit Devkit installed as well.

Running gem install fftw3 produces the following:

Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR:  Error installing fftw3:
ERROR: Failed to build gem native extension.

current directory: C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/fftw3-0.3/ext
C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20180813-7456-1v4icuv.rb extconf.rb
checking for narray.h... yes
checking for narray_config.h... yes
checking for fftw3.h... yes
checking for main() in -lfftw3... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You 
may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=C:/Ruby22-x64/bin/$(RUBY_BASE_NAME)
    --with-narray-dir
    --without-narray-dir
    --with-narray-include
    --without-narray-include=${narray-dir}/include
    --with-narray-lib
    --without-narray-lib=${narray-dir}/lib
    --with-fftw3-dir
    --without-fftw3-dir
    --with-fftw3-include
    --without-fftw3-include=${fftw3-dir}/include
    --with-fftw3-lib
    --without-fftw3-lib=${fftw3-dir}/lib
    --with-fftw3lib
    --without-fftw3lib
** configure error **
Header fftw3.h or the compiled fftw3 library is not found.
If you have the library installed under /fftw3dir (that is, fftw3.h is
in /fftw3dir/include and the library in /fftw3dir/lib/),
try the following:

% ruby extconf.rb --with-fftw3-dir=/fftw3dir

Alternatively, you can specify the two directory separately
with --with-fftw3-include and --with-fftw3-lib.

To see why this extension failed to compile, please check the mkmf.log which 
can be found here:

C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0/fftw3-0.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/fftw3-0.3 for inspection.
Results logged to C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0/fftw3-0.3/gem_make.out

There is a lot in here...So far I've been able to get the fftw3.h file to link properly by reading the mkmf.log file and placing the headers in a path that's searched by the gem installation. I've tried using more of the command line options ruby extconf.rb <opts> to generate the makefile (receiving similar errors), I've placed the DLL in the System32 and SysWOW64 folders.

The same error populates with the ruby-termios gem, but instead it's looking for termios.h. Which lead me to believe there may be something wrong with the gems that need the Devkit to install, so I tried reinstalling it with no luck as well.

So I have a few questions:

  1. Why do the Devkit gems search for header files that match the gem to be installed? (e.g. fftw3 looks for fftw3.h, ruby-termios looks for termios.h) Shouldn't these come bundled with the gem?

  2. Is it possible that libfftw3 is missing a main() function? I'm unsure if the install command can find the dll, or if the dll is missing main(). If this is the case, what would be the work-around for that problem? (I don't want to remove the have_library("fftw3") call from the extconf.rb file as this just feels dirty and all around incorrect.)

  3. Does anyone know the work-around for this error?

Sorry for throwing so much at you and hopefully this is clear enough. Thanks in advance.

EDIT: A couple things to note:

  • On Windows, you can install the fftw3 library during Cygwin's installation
  • gem install also has an option to install --with-fftw3-dir="path"
abullard
  • 1
  • 1
  • https://github.com/evan/fftw3 Looks like that gem has native extensions (as ruby calls them), which means its partly written in C code. Gems with native extensions actually have to compile C code when you install them. Additionally, it looks like fftw3 expects the program's binaries to be installed (http://fftw.org/download.html). Basically, the gem does not install fftw itself, it's just a ruby interface for a program you should already have installed. Do you for sure have the fftw program installed before attempting to install this gem? – Nate Aug 13 '18 at 22:43
  • I did have the library installed, however, no matter what commands I used to point to the library itself, `install` couldn't find it. I did make some progress, see the edit above. I assumed that the gem would bundle the library with it, but this was naive of me. – abullard Aug 14 '18 at 16:42

2 Answers2

0

To answer your questions in order:

  1. (This is actually a few questions) Typically yes, naming convention is of course going to convey something meaningful, but it is not required. It is quite possible to for the author to have changed the name of a file. Ruby simply looks for an entry-point that must be defined Init_gem_name. Other than that, as long it conforms to C standards and the extconfig.rb is properly configured to tell the compiler where to find source files, anything goes. Any C extension is going to have at least one header to define the entry point, but depending on what the gem does, there may be headers not included. For example, if writing a gem that uses OpenGL, it is not always necessary to include the gl.h header, because it is already included with Windows, OSX, and Linux systems by default (though often outdated).
  2. This is so highly unlikely that I am just going to say NO.
  3. You don't need a "work-around", you need only follow the directions given to use the gem. Not all gems are self-contained libraries that have no dependencies, especially anything that wraps a library. This particular gem requires that libfft3 be installed on your system already, where it can be found, before you install the gem, otherwise all the functions that it thinks it has by reading a header file are not actually defined anywhere.
ForeverZer0
  • 2,379
  • 1
  • 24
  • 32
  • Thanks for all the information. Definitely some things I wouldn't have otherwise learned from this problem. Work-around was bad word choice on my part. I was looking for a solution to getting the gems installed. – abullard Aug 14 '18 at 16:45
  • One another note, and this is just a thought not backed by any knowledge of these particular gems, but the `fftw3` gem looks incomplete, and at a glance doesn't look like it had Windows in mind. Are you sure you didn't intend `gem install ruby-fftw3`? – ForeverZer0 Aug 14 '18 at 19:06
  • I needed fftw3, not ruby-fftw3. I've solved the problem though! – abullard Aug 15 '18 at 19:10
0

These steps are for a 64-bit OS with Ruby 2.2.4 and Devkit on Windows 10.

  1. Run Cygwin setup and select mingw64-x86_64-fftw3 (version 3.3.5) for install

  2. Copy C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\lib\libfftw3* to C:\fftw3\lib

  3. Copy C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\include\fftw3* to C:\fftw3\include

  4. Copy C:\COSMOS\Vendor\Ruby\lib\ruby\gems\2.2.0\gems\narray-0.6.1.2\src\libnarray.a to C:\fftw3\lib

  5. Copy both narray.h and narray_config.h from <rubypath>\lib\ruby\gems\2.2.0\gems\narray-0.6.1.2\src to C:\fftw3\include

  6. run gem install fftw3 -- --with-opt-dir=C:\fftw3

  7. Add C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\bin to PATH

These steps will allow the installation of gems that require the fftw3library. You just need to specify the --with-opt-dir option during gem install

abullard
  • 1
  • 1
  • Why did you you install Cygwin if you have DevKit?All of this copying and installing amounts to to just configuring paths. You install Cygwin, then take all the MingW folders from it, which is just a slimmed version of what the DevKit has. You literally only had to configure your paths, and all this proves it more. – ForeverZer0 Aug 15 '18 at 19:29
  • I agree, configuring paths was the answer to the problem. It was all a matter of using the proper libraries though. I was originally using the `fftw3` libraries from the FFTW [website](http://www.fftw.org/install/windows.html), however those didn't work. MingW packaged with the Devkit doesn't include the needed fftw3 libraries. So the solution found came down to Cygwin's installation with the `fftw3` devel. – abullard Aug 16 '18 at 16:36