我在使用 FFTW3 时出现问题,在 Windows 系统上使用 vscode 和 MinGW,c++

问题描述 投票:0回答:1

我是c++编程初学者,最近需要使用FFTW3。所以我从官网下载了Windows-64的预编译版本,使用

dlltool -d libfftw3-3.def libfttw3-3.lib -D libfftw3-3.dll
创建了
.lib
文件。

然后我要求GPT生成一个简单的FFT程序。程序编译成功,但是当我执行

.exe
时,什么也没有发生,连
cout << "Program start" << endl;
也无法工作。

代码:

#include <iostream>
#include <cmath>
#include <vector>
#include <complex>
#include <fftw3.h>

using namespace std;

int main() {
    cout << "Program start." << endl;

    const int N = 100;
    std::vector<double> x(N), y(N);
    
    // define the orginal signal
    for (int i = 0; i < N; ++i) {
        x[i] = i;
        y[i] = std::sin(2 * M_PI * i / N);
    }

    // state the FFT input array
    fftw_complex* y_in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    fftw_complex* y_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    fftw_complex* y_origin = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);

    // Initialize FFT input array
    for (int i = 0; i < N; ++i) {
        y_in[i][0] = y[i];  // Real part
        y_in[i][1] = 0.0;   // Imaginary part
    }

    // create Fourier transformation plans
    fftw_plan plan_forward = fftw_plan_dft_1d(N, y_in, y_out, FFTW_FORWARD, FFTW_ESTIMATE);
    fftw_plan plan_backward = fftw_plan_dft_1d(N, y_out, y_origin, FFTW_BACKWARD, FFTW_ESTIMATE);

    // Fourier transformation
    fftw_execute(plan_forward);

    // Inverse Fourier transformation
    fftw_execute(plan_backward);

    // normalization
    std::vector<double> y_reconstructed(N);
    for (int i = 0; i < N; ++i) {
        y_reconstructed[i] = y_origin[i][0] / N;
    }

    // release the FFTW plans
    fftw_destroy_plan(plan_forward);
    fftw_destroy_plan(plan_backward);
    fftw_free(y_in);
    fftw_free(y_out);
    fftw_free(y_origin);

    cout << "Program end." << endl;

    return 0;
}

我使用

g++ -O2 -g -o a.exe a.cpp -I "C:/fftw" -L "C:/fftw" -lfftw3-3
来编译程序。

我尝试添加更多

cout
但仍然没有发生。我想我链接到fftw时可能是错误的?

更新: 我用GDB运行了

a.exe
,结果发现了一些问题:

[New Thread 19440.0x25e4]
[New Thread 19440.0x36a4]
[New Thread 19440.0x5140]
[Thread 19440.0x5140 exited with code 3221225781]
[Thread 19440.0x57e8 exited with code 3221225781]
[Thread 19440.0x36a4 exited with code 3221225781]
During startup program exited with code 0xc0000135.

我想也许编译器没有找到

.dll
文件

c++ mingw fftw
1个回答
0
投票

我重新检查了GPT,它告诉我将

.dll
文件应该放在
a.exe
的同一目录中。而且它有效,也许我只是缺乏计算机常识。

© www.soinside.com 2019 - 2024. All rights reserved.