简体   繁体   中英

Installing the FFTW3 library on Windows 10 using Code::Blocks (C++)

I want to install the FFTW3 library in my system which runs on Windows 10. My compiler is the minGW GCC 10.1 and I am using Code::Blocks.

I have downloaded the 64bit version from http://www.fftw.org/install/windows.html and unzipped it in C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3 .

Then I followed the steps described here https://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/ . In step 4 it says "Tell the linker where to look for the library file(s) for the library."

Since there is no.lib file, it had to be created. I copied the libfftw3-3.def file and pasted it inside the bin folder of the mingw64 compiler, so that the dlltool can be used. Note that inside the same bin folder there exists the as.exe executable. I added this directory, namely C:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin to system PATH as described in MinGW dlltool creates empty file .

Then I opened the cmd window as admin and executed dlltool -v -d nlib32.def -l nlib32.lib . The 2KB libfftw3-3.lib file was created inside the compiler's bin folder.

Then, again, I followed the steps that are described in the link I provided above. For convinience, I am posting the steps directly below.

Once per library:

  1. Acquire the library. Download it from the website or via a package manager.
  2. Install the library. Unzip it to a directory or install it via a package manager.
  3. Tell the compiler where to look for the header file(s) for the library.

Here I set the path to be C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3

  1. Tell the linker where to look for the library file(s) for the library.

Here I set the path to be C:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin

Once per project:

  1. Tell the linker which static or import library files to link.

Again the path was set to C:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin

  1. #include the library's header file(s) in your program.

  2. Make sure the program know where to find any dynamic libraries being used.

When I execute the following code

#include <iostream>
#include <fftw3.h>

int main(){

    int N = 100;
    fftw_complex *in;
    in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);

}

I am getting the following error: "Undefined reference to '__imp_fftw_malloc' ".

I don't know what I am doing wrong so that the compiler cannot find the function that I am calling, but I guess that the problem is in step 7, that is in the "Make sure the program know where to find any dynamic libraries being used." step. Note that this is the first time I had to deal with dynamic-link libraries etc so I am still confused.

I managed to make your code run in three simple steps (I suppose you have dowloaded and extracted FFTW properly and installed Code::Blocks too):

  1. Indicate the FFTW directory so the header fftw3.h can be read. Build options > Search directories > Compiler and specify where the header file is. To me it's C:\Program Files\FFTW .

  2. Copy the libfftw3-3.dll file from the FFTW directory to next to the .exe of your application. Tp me it's C:\projets\fftwEx\bin\Debug .

  3. Copy and rename the libfftw3-3.dll file in the original installed directory to libfftw3-3.dll.a . Then indicate it's path in Build options > Linker settings > Link libraries. To me it's C:\Program Files\FFTW\libfftw3-3.dll.a .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM