adamstark/Gist

undefined reference error

leonardltk opened this issue · 1 comments

i created a debug_gist.cpp out of, but beside the Gist folder:

#include <iostream>
#include "Gist/src/Gist.h"
#include "Gist/libs/kiss_fft130/kiss_fft.h"
using namespace std;
int main () {
  int frameSize = 512;
  int sampleRate = 44100;
  Gist<float> gist (frameSize, sampleRate);
  return 0 ;
}

When i ran this g++ -DUSE_KISS_FFT debug_gist.cpp, i get the undefined reference errors:

/tmp/ccMjqnF9.o: In function `main':
debug.cpp:(.text+0x4b): undefined reference to `Gist<float>::Gist(int, int, WindowType)'
debug.cpp:(.text+0x5f): undefined reference to `Gist<float>::~Gist()'
collect2: error: ld returned 1 exit status

Edit 1:

I tried to include all the *.cpp files within the src when i compile, (and i added in #include <cstdlib> #include <stddef.h> to all of them)

g++ -DUSE_KISS_FFT \
$(find Gist/src/ -name "*.cpp" ! -path "*Accelerate*") \
debug_gist.cpp

i get the following error

/tmp/ccIkVWzO.o: In function `main':
debug_gist.cpp:(.text+0x0): multiple definition of `main'
/tmp/ccGRWERk.o:debug.cpp:(.text+0x0): first defined here
/tmp/cc0v0kst.o: In function `Gist<float>::configureFFT()':
Gist.cpp:(.text._ZN4GistIfE12configureFFTEv[_ZN4GistIfE12configureFFTEv]+0xb0): undefined reference to `kiss_fft_alloc'
/tmp/cc0v0kst.o: In function `Gist<float>::performFFT()':
Gist.cpp:(.text._ZN4GistIfE10performFFTEv[_ZN4GistIfE10performFFTEv]+0xc5): undefined reference to `kiss_fft'
/tmp/cc0v0kst.o: In function `Gist<double>::configureFFT()':
Gist.cpp:(.text._ZN4GistIdE12configureFFTEv[_ZN4GistIdE12configureFFTEv]+0xb0): undefined reference to `kiss_fft_alloc'
/tmp/cc0v0kst.o: In function `Gist<double>::performFFT()':
Gist.cpp:(.text._ZN4GistIdE10performFFTEv[_ZN4GistIdE10performFFTEv]+0xc9): undefined reference to `kiss_fft'
collect2: error: ld returned 1 exit status

While the problem of undefined reference is gone now,
there is the problem of multiple definition of main,
as well as kiss_fft and kiss_fft_alloc issues.

Edit 2:

I tried to include all the *.cpp files within the src when i compile, (and i added in #include <cstdlib> #include <stddef.h> to all of them)

g++ -DUSE_KISS_FFT \
$(find Gist/src/ -name "*.cpp" ! -path "*Accelerate*") \
Gist/libs/kiss_fft130/kiss_fft.c \
debug_gist.cpp

i get the following error

/tmp/ccS0Symo.o: In function `main':
debug_gist.cpp:(.text+0x0): multiple definition of `main'
/tmp/ccMFylKq.o:debug.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status

While the problem of undefined reference, kiss_fft and kiss_fft_alloc is gone now,
there is still the problem of multiple definition of main.

What is the right way for me to compile this Gist properly?

Hi there, I have now updated the library so that it supports CMake. Alternatively you can just add the files in src to your project. If you need Kiss FFT you will need to add those also (look in the libs folder) and set the appropriate flags and include paths.