How to get FFTW++ working on windows? (for dummies)

泪湿孤枕 提交于 2019-11-27 12:34:56

问题


I'm using Windows 10 and Visual Studio 2015. In C++, I need to get the Fourier-transform of an image for applying filters on it. It seems that FFTW++ is the ideal solution for this, however I can't get it to compile, and its driving me mad. I'm relatively new to programming so I don't know how embarrassing this is.

I used the NuGet function in Visual Studio to get the FFTW library. Since I couldn't find it on NuGet I downloaded the FFTW+ stuff from the following link: https://sourceforge.net/projects/fftwpp/ I copied the content of the download to the project folder, and included the header files in the solution explorer. But it didn't compile, thrown many-many weird errors (for example: in the seconds.h it said that some function which gets the timezone is obsolete, and in the fftww++.h it said that std::max is illegal).

So after seeing that this isn't going to work I went back to the FFTW website, and tried using the Windows installation guide. http://www.fftw.org/install/windows.html I downloaded the 64-bit version, and I have absolutely no idea how to do the library import thing, or even what it does. i.imgur.com/Qs7mFQT.png This is all I get, I'm completely lost.

How can I get it to compile? Please if you can: write me an explanation as detailed as possible on how to use this thing, I may be dumb but I literally have no idea what is going on, and I can't find any tutorial-like on Google.


回答1:


Get the 64bit precompiled FFTW 3.3.5 Windows DLL

  1. Download from fftw-3.3.5-dll64.zip
  2. Unzip the file.

Create the import library (.lib file)

  1. The official FFTW instructions are here.
  2. For background on how to link a DLL to a Visual Studio C++ program this MSDN article Linking an Executable to a DLL especially the part about implicit linking is helpful.
  3. Also helpful, in the unzip location, README-WINDOWS.
  4. Open the Visual Studio Developer Command prompt

    • Navigate to Start -> All Apps -> Visual Studio 2015 -> Developer Command prompt
    • On my machine the location is C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat
  5. Navigate to the unzip location and type

    lib /machine:x64 /def:libfftw3-3.def

(for single or long-double precision use libfftw3f-3.def or libfftw3l-3.def)

  • This will produce libfftw3-3.lib
  • Note this is for x64.

Open Visual Studio and Create a C++ Console Application

  1. Create a C++ Console application
  2. Accept all the default settings
  3. Set the solution platform to x64

Tell Visual Studio where to find the FFTW header file.

(Taken from this SO answer.)

There are various ways to do this, here is one way.

  1. In the solution explorer, right click on the project and select properties.
  2. Add additional include directories. This will be the unzip location.

(Alternatively, the .h file can be copied into the Visual Studio project folder.)

Tell Visual Studio where to find the FFTW import library.

  1. Right click on the project and select properties.
  2. Add additional library directories. This will be the unzip location.
  3. Add additional dependency. Type in the .lib file created earlier (libfftw3-3.lib).

Create a sample program

(From the FFTW tutorial.)

#include "stdafx.h"

#include <fftw3.h>

int main()
{
    fftw_complex *in, *out;
    fftw_plan p;

    int N = 32;

    in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * N);
    out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * N);
    p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);

    fftw_execute(p); /* repeat as needed */

    fftw_destroy_plan(p);
    fftw_free(in); fftw_free(out);

    return 0;
}

Compile

Tell Windows where to find the FFTW DLL The easiest way is to copy the FFTW DLL (libfftw3-3.dll) from the unzip location to the Visual Studio output folder.

  1. In Visual Studio right click on the solution and select Open Folder in File Exporer.
  2. Navigate to the .exe output folder (e.g. fftw_helloworld2\x64\Debug)
  3. Copy the DLL libfftw3-3.dll

Run / Debug

  1. Set a breakpoint
  2. Press F5 or



回答2:


Thanks for this, it solved the issue I was having. Here is my contribution to the answer:

The console application defaults to x86 arch. I had to use the 32-bit dll from the FFTW folks. Make sure you specify /machine:x86 when invoking lib This is with VS2017 community

Ed



来源:https://stackoverflow.com/questions/39675436/how-to-get-fftw-working-on-windows-for-dummies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!