User forums > Help
Installing the FFTW3 library on Windows 10 using Code::Blocks (C++)
Angelos_Fra:
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
--- Code: ---#include <iostream>
#include <fftw3.h>
int main(){
int N = 100;
fftw_complex *in;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
}
--- End code ---
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.
Miguel Gimenez:
With MinGW you can link with the DLL without using a LIB, just put the DLL name in Project -> Buld options -> Linker settings -> Other linker options and the DLL path in Search directories -> Linker
If the link still fails post a full rebuild log in code tags:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F
Angelos_Fra:
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
--- Code: --- #include <fftw3.h>
int main(){
int N = 100;
fftw_complex *in;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
}
--- End code ---
but It won't compile.
Build log:
--- Code: ---
-------------- 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))
--- End code ---
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?
BlueHazzard:
using the dll is wrong in any case. You need the .lib or the .a file. Also this files have to be compatible with the compiler....
Angelos_Fra:
--- Quote from: BlueHazzard on July 09, 2020, 10:57:14 am ---using the dll is wrong in any case. You need the .lib or the .a file. Also this files have to be compatible with the compiler....
--- End quote ---
For windows, I have read that I only need the .lib file. How can I make it compatible with the compiler?
As for the .lib file generation. I did the following:
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.
Is that correct?
EDIT: I have edited my first post as well. There is a description of my first attempt.
Navigation
[0] Message Index
[#] Next page
Go to full version