我正在编译一个测试程序来测试fftw3(ver3.3.4)。由于它不与根安装previlidge我用的命令是:无法链接到fftw3库
gcc -lm -L/home/my_name/opt/fftw-3.3.4/lib/ -I/home/my_name/opt/fftw-3.3.4/include/ fftwtest.c
在库安装
/home/my_name/opt/fftw-3.3.4/
我的代码是fftw3网站上的第一个教程:
#include <stdio.h>
#include <fftw3.h>
int main(){
int n = 10;
fftw_complex *in, *out;
fftw_plan p;
in = (fftw_complex*) fftw_malloc(n*sizeof(fftw_complex));
out = (fftw_complex*) fftw_malloc(n*sizeof(fftw_complex));
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;
}
当我编译程序时,它返回以下错误:
/tmp/ccFsDL1n.o: In function `main':
fftwtest.c:(.text+0x1d): undefined reference to `fftw_malloc'
fftwtest.c:(.text+0x32): undefined reference to `fftw_malloc'
fftwtest.c:(.text+0x56): undefined reference to `fftw_plan_dft_1d'
fftwtest.c:(.text+0x66): undefined reference to `fftw_execute'
fftwtest.c:(.text+0x72): undefined reference to `fftw_destroy_plan'
fftwtest.c:(.text+0x7e): undefined reference to `fftw_free'
fftwtest.c:(.text+0x8a): undefined reference to `fftw_free'
collect2: ld returned 1 exit status
快速搜索意味着我没有正确链接到库,但有趣的是,它不会抱怨fftw_plan和fftw_complex的声明。事实上,如果我删除所有以“fftw_”开头的函数,只保留声明,它将通过编译。
那么我哪里出错了?链接是否正确?任何建议,将不胜感激。
我应该把所有的标志放在C文件的名字后面。 – robinchm 2014-08-29 12:59:30
啊,是的,我经常忘记一个好点。 – downhillFromHere 2014-08-29 13:20:27