I've got undefined reference to 'ffwf_malloc' and other functions fftw3 lib
At first I installed fftw3 library to usr/local/lib
. Then I included <fftw3.h> in my project. But I've got an error: Can't find <fftw3.h> file
. In pro file I added LIBS += -lfftw3. Now I've got no errors before I try to compile project.
My main file looks like this:
#include <QCoreApplication>
#include <bitset>
#include <fftw3.h>
#include "fftlib/fft_internal.h"
#include <stdlib.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
cfloat *input = static_cast<cfloat*>(fftwf_malloc(64 * sizeof(cfloat)));
cfloat *output = static_cast<cfloat*>(fftwf_malloc(64 * sizeof(cfloat)));
fftwf_plan plan;
plan = fftwf_plan_dft_1d(64, reinterpret_cast<fftwf_complex *>(input), reinterpret_cast<fftwf_complex *>(output), FFTW_FORWARD, FFTW_MEASURE);
srand(0);
for (unsigned i = 0; i < 64; i++)
{
float real = (float)rand() / RAND_MAX - 0.5f;
float imag = (float)rand() / RAND_MAX - 0.5f;
input[i] = cfloat_create(real, imag);
}
fftwf_execute(plan);
fftwf_free(input);
fftwf_free(output);
fftwf_destroy_plan(plan);
return a.exec();
}
.pro file: QT -= gui
CONFIG += c++17 console
CONFIG -= app_bundle
LIBS += -L usr/local/lib/ -lfftw3
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
fftlib/cpu.c \
fftlib/fft.c \
fftlib/kernel.c \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
fftlib/fft.h \
fftlib/fft_internal.h
I tried to change path usr/local/lib/ to usr/local/lib/cmake/fftw3. But it still doesn't work.
In actually, I wanted to use fftw3f library, but I tried to use fftw3. I did not know there is fftw3f library. I don’t know why, but functions of fftw3f library have got definitions in fftw3. That’s why framework does not mark them as errors. There were no problem in path to the lib. I installed fftw3f and it work correctly.