在官网下载了压缩包后
按照教程只需要三步安装
./configure
make
make install
make install 时遇到了错误:
make[3]: *** [install-includeHEADERS] Error 1 make[3]: Leaving directory `/home/user307/straw/fftw-3.3.8/api’
后来又找了博客上的教程https://blog.csdn.net/wbgxx333/article/details/36625977
- 下载 fftw-2_1_3_tar.gz (www.fftw.org, or www.rpmfind.net )
- tar zxvf fftw-2_1_3_tar.gz 展开压缩文件
- 在Linux中安装FFTW:
a. ./configure --enable-type-prefix --prefix=/usr/local/fftw --with-gcc --disable-fortran --enable-i386-hacks
其中,–enable-type-prefix 参数是为了同时使用single precision(单精度)和double precision(双精度),如果不使用它,最后只有以rfftw开头的文件被安装(real fftw);
–prefix= 参数是设定安装目录;
–with-gcc 使用gcc编译器;
–disable-fortran 参数为了不包含Fortran调用的机制;
–enable-i386-hacks 为Pentium和x86以后的CPU优化gcc的编译速度。
b.make 编译
c.make install 安装,这一次安装完后,在安装目录中存在以dfftw和drfftw开头文件,但没有sfftw开头的文件
d.make clean 还需要安装一次,先清除
e…/configure --enable-float --enable-type-prefix --prefix=/usr/local/fftw --with-gcc --disable-fortran --enable-i386-hacks
其中,–enable-float 为了生成单精度计算的头文件和库文件,即以sfftw开头的文件。
f.make 重新编译
g.make install 再一次安装,安装完后,目录中便会同时存在sfftw和dfftw开头的文件(用于复数函数/complex function的FFT变换)和srfftw与drfftw开头的文件(用于实数函数的FFT变换)
例如,如果需要用到双精度的实数FFT变换/FFTs,那么在编译的链接命令中需要按如下顺序加入
-ldrfftw -ldfftw参数
下面的是如何使用的一个例子
/*****************************
- filename: test_fftw.cpp
- author : Tiao Lu
- Company : School of Mathematical Sciences, Peking University
- 编译命令: g++ -o test_fftw.exe test_fftw.cpp -lfftw3
- Date : September 30th, 2007
- Description: This code is an example to show the use of the free code FFTW, which implements the Fast Fourier Trasformation algorithm.
*/
#include
#include <fftw3.h>
#include <math.h>
#include
#define N 10
using namespace std;
int main(int argc, char * argv[]){
fftw_complex in[N], out[N];
fftw_plan p;
//一维dft,in 输入,out输出,FFTW_FORWARD 表示 exp 上指数是负号
// out = F in
//where out and in are two vectors of the same length n, and F is a n-by-n matrix with the (j,k) element
// F jk = exp(-i 2 pi j k /n). i 是虚数单位.
p=fftw_plan_dft_1d(N,in,out,FFTW_FORWARD,FFTW_MEASURE);
for(int i=0;i <N;i ++) {
in[i][0]=i;
in[i][1]=0.0;
}
fftw_execute(p);
for(int i=0;i <N;i ++){
cout<<out[i][0]<<" "<<out[i][1]<<endl;
}
//验证是否 out[3] = \sum_{k=0}^{N-1}exp(-i 2pi 3 k/N)in[k]
complex<double> temp = 0.0;
for(int k =0; k < N; k ++){
double pi = 4*atan(1.0);
temp += exp(complex<double>(0.0,-2.0*pi*3*k/N))*complex<double>(in[k][0],in[k][1]);
}
cout<<"out[3] is "<<temp<<endl;
fftw_complex out1[N];
fftw_plan p1;
//一维dft,in 输入,out输出,FFTW_BACKWARD 表示 exp 上指数是正号
// out = IF in
//where out and in are two vectors of the same length n, and IF is a n-by-n matrix with the (j,k) element
// IF jk = exp( +i 2 pi jk/n). i 是虚数单位.
p1=fftw_plan_dft_1d(N,out1,in,FFTW_BACKWARD,FFTW_MEASURE);
for(int i=0;i <N;i ++){
out1[i][0]=out[i][0];
out1[i][1]=out[i][1];
}
fftw_execute(p1);
//注意这里得到的 in 并不是和原来的in 的数值不同,比较之后发现,现在的in
// 是原来的 in 的 N 倍。原因是这里的定义的逆傅立叶变换没有除以 N.
//这和课本中定义的逆傅立叶变换不同。
for(int i=0;i <N;i ++){
cout<<in[i][0]<<" "<<in[i][1]<<endl;
}
fftw_destroy_plan(p);
fftw_destroy_plan(p1);
return 1;
}
解决permission denied的错误:
sudo make;
sudo make install;
安装后没有出现error但是运行时显示找不到fftw.h
未链接函数库:在指令后面加上-I/usr/local/fftw/include -lfftw3 -L/usr/local/fftw/lib
/include为头文件所在的目录
/lib为fftw的代码库真正所在的目录
用的以下方法没有解决问题
查了资料进入了/api目录下进行make install
又发生了permission denied的错误
最后的解决方法:
./configure --prefix=/tmp/local-install
make
make install
这三行代码将程序安装到/tmp/local-install目录。
因为需要将root写给/usr。如果要将程序安装到非标准位置,则需要使用–prefix。
http://fftw.org/fftw3_doc/Installation-on-Unix.html#Installation-on-Unix