undefined reference to `kiss_fft_alloc'
busFred opened this issue · 1 comments
busFred commented
Hello,
I modified the CMakeLists.txt inside the src folder to the following so that I can include the header file as a library.
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../libs/kiss_fft130)
add_library (
Gist STATIC
AccelerateFFT.cpp
AccelerateFFT.h
CoreFrequencyDomainFeatures.cpp
CoreFrequencyDomainFeatures.h
CoreTimeDomainFeatures.cpp
CoreTimeDomainFeatures.h
Gist.cpp
Gist.h
MFCC.cpp
MFCC.h
OnsetDetectionFunction.cpp
OnsetDetectionFunction.h
WindowFunctions.cpp
WindowFunctions.h
Yin.cpp
Yin.h
)
target_include_directories (${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
source_group (Source src)
target_compile_definitions (Gist PUBLIC -DUSE_KISS_FFT)
This is the CMakeLists.txt in the folder that contains my main function.
add_executable(plot_fourier_transform plot_fourier_transform.cpp)
target_compile_options(plot_fourier_transform PRIVATE)
target_include_directories(plot_fourier_transform
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../../include"
)
target_link_libraries(plot_fourier_transform
PRIVATE
AudioFile
Gist
Python3::Python
Python3::NumPy
)
set_target_properties(plot_fourier_transform
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin"
OUTPUT_NAME "plot_fourier_transform"
SUFFIX ".o"
)
This is the content of my code:
#include <plot_fourier_transform/plot_fourier_transform.hpp>
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "./plot_fourier_transform.o /path/to/*.wav" << std::endl;
exit(EXIT_FAILURE);
}
AudioFile<double> audio_file;
audio_file.load(argv[1]);
audio_file.printSummary();
int frame_size = audio_file.getNumSamplesPerChannel();
int sample_rate = audio_file.getSampleRate();
Gist<double> gist(frame_size, sample_rate);
gist.processAudioFrame(audio_file.samples[0]);
const std::vector<double>& magnitude_spectrum = gist.getMagnitudeSpectrum();
matplotlibcpp::figure();
matplotlibcpp::title("Magnitude Spectrum");
matplotlibcpp::plot(magnitude_spectrum);
matplotlibcpp::show();
}
This is the header file plot_fourier_transform.hpp:
#define INCLUDE_PLOT_SOUND_WAVE_HPP_
#include <iostream>
#include <vector>
#include <AudioFile.h>
#include <matplotlibcpp.h>
#endif // INCLUDE_PLOT_SOUND_WAVE_HPP_
#ifndef INCLUDE_PLOT_SOUND_WAVE_HPP_
#define INCLUDE_PLOT_SOUND_WAVE_HPP_
#include <iostream>
#include <vector>
#include <AudioFile.h>
#include <matplotlibcpp.h>
#endif // INCLUDE_PLOT_SOUND_WAVE_HPP_
Here is the error I received. It seems the linker cannot find kiss_fft library correctly. I tried to add #define USE_KISS_FFT by brute force, but cmake tells me that USE_KISS_FFT is already defined if I do it this way.
[main] Building folder: sound_detection clean
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/fred/Documents/Research/sound_detection/build --config Debug --target clean --
[build] [1/1 100% :: 0.008] Cleaning all built files...
[build] Cleaning... 22 files.
[build] Build finished with exit code 0
[main] Building folder: sound_detection
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/fred/Documents/Research/sound_detection/build --config Debug --target all -- -j 6
[build] [6/23 4% :: 4.604] Building CXX object third_party_libraries/AudioFile/tests/CMakeFiles/Tests.dir/GeneralTests.cpp.o
[build] [7/23 8% :: 4.755] Building CXX object third_party_libraries/Gist/src/CMakeFiles/Gist.dir/AccelerateFFT.cpp.o
[build] [8/23 13% :: 4.830] Building CXX object third_party_libraries/AudioFile/tests/CMakeFiles/Tests.dir/FileWritingTests.cpp.o
[build] [9/23 17% :: 4.967] Building CXX object third_party_libraries/AudioFile/examples/CMakeFiles/Examples.dir/examples.cpp.o
[build] [10/23 21% :: 5.282] Building CXX object third_party_libraries/AudioFile/tests/CMakeFiles/Tests.dir/AiffLoadingTests.cpp.o
[build] [11/23 26% :: 5.307] Linking CXX executable third_party_libraries/AudioFile/examples/Examples
[build] [12/23 30% :: 5.453] Building CXX object third_party_libraries/AudioFile/tests/CMakeFiles/Tests.dir/WavLoadingTests.cpp.o
[build] [13/23 34% :: 5.480] Building CXX object third_party_libraries/Gist/src/CMakeFiles/Gist.dir/CoreTimeDomainFeatures.cpp.o
[build] [14/23 39% :: 5.575] Building CXX object third_party_libraries/Gist/src/CMakeFiles/Gist.dir/CoreFrequencyDomainFeatures.cpp.o
[build] [15/23 43% :: 6.326] Building CXX object third_party_libraries/Gist/src/CMakeFiles/Gist.dir/OnsetDetectionFunction.cpp.o
[build] [16/23 47% :: 6.421] Building CXX object third_party_libraries/Gist/src/CMakeFiles/Gist.dir/WindowFunctions.cpp.o
[build] [17/23 52% :: 6.697] Building CXX object third_party_libraries/Gist/src/CMakeFiles/Gist.dir/Yin.cpp.o
[build] [18/23 56% :: 6.742] Building CXX object third_party_libraries/Gist/src/CMakeFiles/Gist.dir/Gist.cpp.o
[build] [18/23 60% :: 6.960] Building CXX object third_party_libraries/Gist/src/CMakeFiles/Gist.dir/MFCC.cpp.o
[build] [19/23 65% :: 7.165] Linking CXX static library third_party_libraries/Gist/src/libGist.a
[build] [19/23 69% :: 8.961] Building CXX object src/CMakeFiles/main.dir/main.cpp.o
[build] [20/23 73% :: 9.200] Linking CXX executable ../bin/sound_detection_main.o
[build] [20/23 78% :: 9.336] Building CXX object third_party_libraries/AudioFile/tests/CMakeFiles/Tests.dir/main.cpp.o
[build] [21/23 82% :: 9.609] Building CXX object src/plot_fourier_transform/CMakeFiles/plot_fourier_transform.dir/plot_fourier_transform.cpp.o
[build] [22/23 86% :: 9.698] Linking CXX executable third_party_libraries/AudioFile/tests/Tests
[build] [22/23 91% :: 9.806] Building CXX object src/plot_sound_wave/CMakeFiles/plot_sound_wave.dir/plot_sound_wave.cpp.o
[build] [23/23 95% :: 9.871] Linking CXX executable ../src/bin/plot_fourier_transform.o
[build] FAILED: ../src/bin/plot_fourier_transform.o
[build] : && /bin/g++-9 -g -rdynamic src/plot_fourier_transform/CMakeFiles/plot_fourier_transform.dir/plot_fourier_transform.cpp.o -o ../src/bin/plot_fourier_transform.o third_party_libraries/Gist/src/libGist.a /usr/lib/x86_64-linux-gnu/libpython3.8.so && :
[build] /usr/bin/ld: third_party_libraries/Gist/src/libGist.a(Gist.cpp.o): in function `Gist<float>::configureFFT()':
[build] /home/fred/Documents/Research/sound_detection/build/../third_party_libraries/Gist/src/Gist.cpp:264: undefined reference to `kiss_fft_alloc'
[build] /usr/bin/ld: third_party_libraries/Gist/src/libGist.a(Gist.cpp.o): in function `Gist<float>::performFFT()':
[build] /home/fred/Documents/Research/sound_detection/build/../third_party_libraries/Gist/src/Gist.cpp:326: undefined reference to `kiss_fft'
[build] /usr/bin/ld: third_party_libraries/Gist/src/libGist.a(Gist.cpp.o): in function `Gist<double>::configureFFT()':
[build] /home/fred/Documents/Research/sound_detection/build/../third_party_libraries/Gist/src/Gist.cpp:264: undefined reference to `kiss_fft_alloc'
[build] /usr/bin/ld: third_party_libraries/Gist/src/libGist.a(Gist.cpp.o): in function `Gist<double>::performFFT()':
[build] /home/fred/Documents/Research/sound_detection/build/../third_party_libraries/Gist/src/Gist.cpp:326: undefined reference to `kiss_fft'
[build] collect2: error: ld returned 1 exit status
[build] [23/23 100% :: 9.953] Linking CXX executable ../bin/plot_sound_wave.o
[build] ninja: build stopped: subcommand failed.
[build] Build finished with exit code 1
Would you be able to help me figure out what is going on?
busFred commented
I figured it out
It turns out that I didn't add the CMakeLists.txt for the kiss_fft library