gpt4 book ai didi

c++ - FFTW 在 Windows 机器上链接 g++ 错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:29:19 25 4
gpt4 key购买 nike

我正在尝试学习在 Windows 机器上使用 FFTW,从 Windows 命令行使用 g++ 进行编译。我已经阅读了 FFTW 手册并搜索了论坛,但似乎没有什么与我的问题相同。我想我不明白如何正确链接到 FFTW 库。我已经下载了 FFTW3.zip 文件并将所有文件复制到我的 .cpp 文件所在的目录中。我的简单示例是使用提供的代码转换正弦波:

#include<iostream>
#include<math.h>
#include<string.h>
#include<studio.h>
#include<bits/stdc++.h>
#include<fftw3.h>



int main(){
int length = 1000;
fftw_complex time[length];
fftw_complex signal[length];
fftw_complex fftsignal[length];
double omega = 1;
for (int i=0;i<length;i++){
time[i][0] = 0.1*i;
time[i][1] = 0;
signal[i][0] = sin(time[i][0]*omega);
signal[i][1] = 0;
}

ofstream savefile;
string name = "sinwave.txt";
savefile.open(name);
for (int i=0;i<length;i++){
savefile <<time[i][0]<<"\t"<<signal[i][0]<<endl;
}
savefile.close();

fftw_plan my_plan;

my_plan = fftw_plan_dft_1d(length,signal,fftsignal,FFTW_FORWARD,FFTW_ESTIMATE);

fftw_execute(my_plan);
fftw_destroy_plan(my_plan);
fftw_free(signal);
fftw_free(fftsignal);
}

我用来编译的命令是:

g++ -I..filepath..\\"FFTW learning" -L..filepath..\\"FFTW learning" -std=c++11 FFTW.cpp -Lfftw3 -lm

该错误为我提供了对无法在 fftw3 文件或我自己的文件中找到的各种对象的多个 undefined reference 。它在错误的最后一行进一步指出“最终链接失败”。

C:\Users\1915821\AppData\Local\Temp\ccnK99CJ.o:FFTW.cpp:(.text+0x1408): undefined reference to `__imp_fftw_plan_dft_1d'
C:\Users\1915821\AppData\Local\Temp\ccnK99CJ.o:FFTW.cpp:(.text+0x1422): undefined reference to `__imp_fftw_execute'
C:\Users\1915821\AppData\Local\Temp\ccnK99CJ.o:FFTW.cpp:(.text+0x1435): undefined reference to `__imp_fftw_destroy_plan'
C:\Users\1915821\AppData\Local\Temp\ccnK99CJ.o:FFTW.cpp:(.text+0x1448): undefined reference to `__imp_fftw_free'
C:\Users\1915821\AppData\Local\Temp\ccnK99CJ.o:FFTW.cpp:(.text+0x145b): undefined reference to `__imp_fftw_free'
c:/programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\1915821\AppData\Local\Temp\ccnK99CJ.o: bad reloc address 0x0 in section `.pdata'
c:/programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

我也试过对链接使用大写和小写-l的所有组合,都返回错误

cannot find -lfftw3

如果有人知道如何正确链接到这些库或能找出我的链接不起作用的原因,我将感谢您的帮助。谢谢。

最佳答案

因为它是在 Windows 上,我怀疑 fftw 是作为 .lib 文件提供的。在这种情况下,您不能只使用 -l(仅适用于 .a 和 .so 文件),您需要使用 -llibfftw3。这偏离了惯例,但 Mingw 也有同样的说法。

关于c++ - FFTW 在 Windows 机器上链接 g++ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59289435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com