c++lnk2019spectrogramkissfft

LNK2019: unresolved external symbol _kiss_fftr_alloc referenced in function "void __cdecl mainfunc(void)


I have been trying to use Kiss FFT in my project. I cloned this repository in my project folder: https://github.com/mborgerding/kissfft

and I followed this link to use it in my project: https://github.com/berndporr/kiss-fft

I am using Clion to build this project. My code is as following:

void mainfunc()
{
    SetConsoleTitleA("PCM Audio Example");

int nfft = 1920;

int is_inverse_fft;


kiss_fftr_cfg cfg = kiss_fftr_alloc(nfft, is_inverse_fft, 0, 0);

kiss_fft_scalar* cx_in = new kiss_fft_scalar[nfft];
kiss_fft_cpx* cx_out = new kiss_fft_cpx[nfft / 2 + 1];


std::string filename = "mixed";

BitDepth* server_buffer = new BitDepth[NUM_SAMPLES];
BitDepth* client_buffer = new BitDepth[NUM_SAMPLES];

BitDepth* buffer = new BitDepth[528000];

memset(server_buffer, 0, NUM_SAMPLES * sizeof(BitDepth));
memset(client_buffer, 0, NUM_SAMPLES * sizeof(BitDepth));

memset(buffer, 0, NUM_SAMPLES * sizeof(BitDepth));

server_sineWave(server_buffer, 500.0);
client_sineWave(client_buffer, 0.0);

mix(buffer, server_buffer, client_buffer, 200);

/* Here mixing is done and output is in buffer array */


for (int i = 0; i < 528000; i++)
{
    cx_in[i] =static_cast<float>(buffer[i]);
}


kiss_fftr(cfg, cx_in, cx_out);

for (int i = 0; i < (nfft / 2 + 1); i++)
{
    cout << "Real value :  " << cx_out[i].r << " Imaginary Value : " << cx_out[i].i << endl;
}


writeWaveFile(std::string(filename + std::string(".wav")).c_str(), buffer);
delete[] buffer;

std::cout << filename << ".wav written!" << std::endl;
std::cin.get();

}

CMakeLists.txt is as :

cmake_minimum_required(VERSION 3.13)
project(beep)

set(CMAKE_CXX_STANDARD 14)

include_directories(kissfft kissfft/test kissfft/tools)
add_executable(beep Beep_Generator.cpp)

and project directory is as :

enter image description here

When I build this code, I get following error:

 error LNK2019: unresolved external symbol _kiss_fftr_alloc referenced in function "void __cdecl mainfunc(void)" (?mainfunc@@YAXXZ)
beep.exe : fatal error LNK1120: 1 unresolved externals

I have used both MSVC and MinGW(g++) to compile this code but in both cases I am getting same error.

How can I resolve this issue ?


Solution

  • I solved it my self. I just made a slight modifications in the CmakeLists.txt as:

    cmake_minimum_required(VERSION 3.13)
    project(beep)
    set(CMAKE_CXX_STANDARD 14)
    link_directories(C:/MinGW/lib)
    find_package (Python3 COMPONENTS Interpreter NumPy)
    include_directories(C:/Python37/include/)
    link_libraries(C:/Python37/libs/libpython37.a Python3::NumPy)
    include_directories( kissfft kissfft/tools matplotlib-cpp )
    add_executable(beep kissfft matplotlib-cpp  kissfft/tools/kiss_fftr.c  kissfft/_kiss_fft_guts.h Beep_Generator.cpp plottingVector.h)
    

    In my project, I really don't know why this was happening but I couldn't able to use both KISS_FFT and KISS_FFTR (the one I required). So when I included only Kiss_fftr.c file in my cmakelists.txt. It solved my error.