Can't link kissfft library

Hi all,

I am on Windows and have built kissfft from https://github.com/mborgerding/kissfft but when I try to build an actual program with it, I cannot get past some linker errors. I'm probably doing something silly, but figured I'd ask...

I build kissfft using cmake:
> C:\moo\libraries\kissfft-master>mkdir build && cd build
> C:\moo\libraries\kissfft-master\build>cmake -G "MinGW Makefiles" -DKISSFFT_OPENMP=ON -DKISSFFT_TOOLS=OFF -DKISSFFT_TEST=OFF -DCMAKE_CXX_COMPILER=C:/moo/MinGW/bin/g++.exe -DCMAKE_C_COMPILER=C:/moo/MinGW/bin/gcc.exe -DPKG_CONFIG_EXECUTABLE="C:/moo/libraries/pkg-config/pkg-config.exe" ..
> make all

This appears to have succeeded, generating files such as:
> "C:\moo\libraries\kissfft-master\build\libkissfft-float-openmp.dll"
> "C:\moo\libraries\kissfft-master\build\libkissfft-float-openmp.dll.a"

Both of these files contains strings such as "kiss_fft_alloc".

Then, I attempt to build the following file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <kiss_fft.h>

#include <iostream>

int main()
{
	std::cout << "C++" << std::endl;

	const int NFFT = 1024;
	
	kiss_fft_cpx cx_in[NFFT] { };
	kiss_fft_cpx cx_out[NFFT] { };
	
	int is_inverse_fft = 0; // false
	
	kiss_fft_cfg cfg = kiss_fft_alloc(NFFT, is_inverse_fft, nullptr, nullptr);

	// ... // put kth sample in cx_in[k].r and cx_in[k].i

	kiss_fft(cfg, cx_in, cx_out);
	
	// ... // transformed. DC is in cx_out[0].r and cx_out[0].i 
	
	kiss_fft_free(cfg);
}


with:

g++ -fdiagnostics-color=always -LC:/moo/libraries/kissfft-master/build" -lkissfft-float-openmp -IC:/moo/libraries/kissfft-master -g test_kissfft.cpp -o test_fft.exe


Note: C:/moo/libraries/kissfft-master contains kiss_fft.h

I get the following errors:


C:/moo/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Moo\AppData\Local\Temp\cc4tm3gT.o: in function `main':
C:/moo/code/test_kissfft/test_kissfft.cpp:17:(.text+0xa0): undefined reference to `kiss_fft_alloc'
C:/moo/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/moo/code/test_kissfft/test_kissfft.cpp:21:(.text+0xc4): undefined reference to `kiss_fft'
collect2.exe: error: ld returned 1 exit status


Any idea why it isn't able to link to kiss_fft_alloc() or kiss_fft()?

I should really just give up on Windows one of these days and just switch to a linux distro.
Last edited on
Update: After a bit of tinkering, I got it to compile and link, although part of me doesn't believe I did it "the right way".

I found this: https://sourceforge.net/p/kissfft/discussion/278332/thread/9fcbca9c/
Claudio - 2018-04-27

I found the solution, here is the explanation :

kiss_fft.h ( it only has definitions)
kiss_fft.c ( it is the real library with functions, we were missing this file )

it worked fine when compiling :

gcc -o example example.c kiss_fft.c -lm

Now it works great.

Regards,

Claudio



Thus, I manually copied kiss_fft.c into my project directory where I have test_kissfft.cpp, and ran:
g++ -fdiagnostics-color=always -LC:/moo/libraries/kissfft-master/build -lkissfft-float-openmp -IC:/moo/libraries/kissfft-master -g test_kissfft.cpp -o test_fft.exe kiss_fft.c


and now it built. Feels eww, but whatever, it works, and I can replace it with another FFT library in the future if need be.
I think it might be a link order problem. Try re-ordering the command line arguments to put the source file before the library, like this:
g++ -fdiagnostics-color=always -LC:/moo/libraries/kissfft-master/build" -IC:/moo/libraries/kissfft-master -g test_kissfft.cpp -lkissfft-float-openmp -o test_fft.exe

I believe the linker ld scans through libraries & object code in the order it appears on the command line, maintaining a list of unresolved symbols as it goes. If the linker processes the library first, it won't remember kiss_fft_alloc because this function hasn't appeared in the list of unresolved symbols yet.
Registered users can post here. Sign in or register to post.