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.
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)
4) 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:
5) 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)
6) #include the library’s header file(s) in your program.
7) 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 am running Code::Blocks version 17.12 on
Windows 10. The compiler I use is minGW64
version 10.1
I am trying to compile the following code #include <fftw3.h>
int main(){
int N = 100;
fftw_complex *in;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
}
but It won't compile.
Build log:
-------------- Clean: Debug in test (compiler: MINGW64)---------------
Cleaned "test - Debug"
-------------- Build: Debug in test (compiler: MINGW64)---------------
x86_64-w64-mingw32-g++.exe -Wall -fexceptions -g -I..\myHeader_Files -I"..\..\..\..\..\..\..\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\eigen-3.3.7" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\armadillo_lib\include" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\spectra-0.8.1\include" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -c "C:\Users\User\Documents\SU MASTER'S\Masters thesis\Code\mySource_Codes\Mesh2D.cpp" -o obj\Debug\mySource_Codes\Mesh2D.o
x86_64-w64-mingw32-g++.exe -Wall -fexceptions -g -I..\myHeader_Files -I"..\..\..\..\..\..\..\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\eigen-3.3.7" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\armadillo_lib\include" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\spectra-0.8.1\include" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -c "C:\Users\User\Documents\SU MASTER'S\Masters thesis\Code\mySource_Codes\V3Lib.cpp" -o obj\Debug\mySource_Codes\V3Lib.o
x86_64-w64-mingw32-g++.exe -Wall -fexceptions -g -I..\myHeader_Files -I"..\..\..\..\..\..\..\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\eigen-3.3.7" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\armadillo_lib\include" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\spectra-0.8.1\include" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -c "C:\Users\User\Documents\SU MASTER'S\Masters thesis\Code\mySource_Codes\Vector.cpp" -o obj\Debug\mySource_Codes\Vector.o
x86_64-w64-mingw32-g++.exe -Wall -fexceptions -g -I..\myHeader_Files -I"..\..\..\..\..\..\..\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\eigen-3.3.7" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\armadillo_lib\include" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\spectra-0.8.1\include" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -c "C:\Users\User\Documents\SU MASTER'S\Masters thesis\Code\mySource_Codes\Vector3D.cpp" -o obj\Debug\mySource_Codes\Vector3D.o
x86_64-w64-mingw32-g++.exe -Wall -fexceptions -g -I..\myHeader_Files -I"..\..\..\..\..\..\..\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\eigen-3.3.7" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\armadillo_lib\include" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\spectra-0.8.1\include" -I"C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -c "C:\Users\User\Documents\SU MASTER'S\Masters thesis\Code\test\main.cpp" -o obj\Debug\test\main.o
x86_64-w64-mingw32-g++.exe -L"..\..\..\..\..\..\..\Program Files (x86)\CodeBlocks\myLibraries\FFTW3" -LC:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin -o bin\Debug\test.exe obj\Debug\mySource_Codes\Mesh2D.o obj\Debug\mySource_Codes\V3Lib.o obj\Debug\mySource_Codes\Vector.o obj\Debug\mySource_Codes\Vector3D.o obj\Debug\test\main.o libfftw3-3.dll
C:\Users\User\Documents\SU MASTER'S\Masters thesis\Code\test\main.cpp: In function 'int main()':
C:\Users\User\Documents\SU MASTER'S\Masters thesis\Code\test\main.cpp:65:19: warning: variable 'in' set but not used [-Wunused-but-set-variable]
65 | fftw_complex *in;
| ^~
x86_64-w64-mingw32-g++.exe: error: libfftw3-3.dll: No such file or directory
Process terminated with status 1 (0 minute(s), 1 second(s))
1 error(s), 1 warning(s) (0 minute(s), 1 second(s))
I have downloaded and unzipped the fftw3-3 library inside a folder. Then, I went to
Settings -> Compiler -> Search Directories -> Compiler Tab and set the path to the folder mentioned above containing the fftw3.h header file.
Then, I went to
Project -> Build Options -> Search Directories -> Compiler Tab and added the path to the fftw3 folder (same as above).
Then, I went to
Project -> Build Options -> Linker Setings-> Other Linker Options and wrote "libfftw3-3.dll" (tried with "libfftw3-3" as well)
Finally, I went to Project -> Build Options -> Search Directories -> Linker Tab and added the path to the fftw3 folder (same as above).
As described in my first post, I also tried to link the library using a .lib file. This did not work either. What am I doing wrong?
In the compiler search dialog you have the FTW3 folder twice, one absolue and one relative:
"C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3"
"..\..\..\..\..\..\..\Program Files (x86)\CodeBlocks\myLibraries\FFTW3"
In the linker search path you have only the relative version. Both versions have spaces, this sometimes confuses the tools. Try copying the dll to another folder (p.e. c:\temp) and update the linker search path.
For windows, I have read that I only need the .lib file.
No.
This is true if you use the visual studio compiler (Microsoft) and if you want to use with it a static library.
For MinGW compiler, the dll is sufficient for a dynamic linking (64 bits in your case). If you want to link statically, you need a static library with the .a extension.
A .lib library may work with MinGW, but I don't think it's recommended.
I have just created a test project. The linker search path is not enough, you must put the absolute path of the DLL in Project -> Buld options -> Linker settings -> Other linker options.
In my case I put G:\Librerias81\fftw-3.3.5\libfftw3-3.dll and it compiles OK. You can also define a global variable and write $(#fftw.lib)\libfftw3-3.dll
#include <stdio.h>
#include <stdlib.h>
#include <fftw3.h>
int main()
{
int N = 100;
fftw_complex *in;
in = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);
fftw_free(in);
return 0;
}
I am reporting below what I have done and it finally worked. The following instructions are based in the guide that can be found at https://www.learncpp.com/cpp-tutorial/a1-static-and-dynamic-libraries/.
1 ) Download the precompiled library .zip found in http://www.fftw.org/install/windows.html
2 ) Unzip into a new folder named "FFTW3" and place it wherever you like, for example C://myLibraries//FFTW3.
3 ) Copy the libfftw3-3.def file and paste it inside the "bin" folder that can be found inside the folder where your compiler is. For example, in my case C:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin
4 ) Put the directory of step 3 to system PATH. You can easily find instructions on web, especialy for windows 10.
5 ) Open the command window and change your directory to the one in step 3. Then execute: dlltool -v -d libfftw3-3.def -l libfftw3-3.a
6 ) Now you can delete the libfftw3-3.def file from the compiler's bin directory and cut the libfftw3-3.a file that was created in there and paste it inside the directory in step 2. I created a folder named "Lib" so, in my case, the directory is C://myLibraries//FFTW3//Lib.
7 ) Open Code::Blocks and go to settings -> compiler -> Search directories ->compiler Tab and add the directory of step 2, namely the location where the header file .h is located.
8 ) Go to Settings -> Compiler -> Search directories -> Linker and add the directory where the .a file is located (see step 6).
9 ) Go to Project -> Build options -> Search directories -> Compiler and add the directory of step 2.
10 ) Go to Project -> Build options -> Search directories -> Linker and add the directory of step 6.
11 ) Go to Project -> Build options -> Linker settings and add the file .a (you have to literally select the file .a, not the folder where it can be found).
12 ) Copy the libfftw3-3.dll that can be found inside the FFTW3 folder and paste it inside the folder where the main.cpp is.
Now the following test code should be working fine.
#include <fftw3.h>
int main()
{
int N = 100;
fftw_complex *in;
in = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);
fftw_free(in);
return 0;
}