kfrlib / kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
https://www.kfrlib.com
GNU General Public License v2.0
1.64k stars 252 forks source link

Compiler can't find convolve_filter's function implementations on MSYS2 #125

Closed nsdrozario closed 3 years ago

nsdrozario commented 3 years ago

I'm on Clang 11.0.0 on MSYS2 using KFR 4.2.0. I made a minimal test of convolve_filter:

#define KFR_ENABLE_WAV 1
#include <kfr/all.hpp>
using namespace kfr;

int main () {

    univector2d<float> impulse;
    univector2d<float> audio;
    univector<float> mixed_impulse;
    univector<float> mixed_audio;
    audio_reader_wav<float> reader(open_file_for_reading("ir.wav"));
    audio_reader_wav<float> reader2(open_file_for_reading("input.wav"));
    audio_writer_wav<float> writer(open_file_for_writing("output.wav"), reader.format());

    for (size_t i = 0; i < impulse.size(); i++) {
        mixed_impulse += impulse[i];
    }

    for (size_t i = 0; i < audio.size(); i++) {
        mixed_audio += audio[i];
    }

    convolve_filter<float> f (mixed_impulse);
    f.apply(mixed_audio);

    writer.write(mixed_audio);

    return 0;

}

Then I compiled with:

clang++ min.cpp -o min.exe -I/usr/local/include -L/usr/local/lib -lkfr_dft -lkfr_io -std=c++17

and got this error:

D:\msys64\mingw64\bin\ld: D:\msys64\tmp\min-c3cf3b.o:min.cpp:(.text+0x4c6): undefined reference to `kfr::sse2::convolve_filter<float>::convolve_filter(kfr::univector<float const, 0ull> const&, unsigned long long)'
D:\msys64\mingw64\bin\ld: D:\msys64\tmp\min-c3cf3b.o:min.cpp:(.text$_ZN3kfr4sse215convolve_filterIfE18process_expressionEPfRKNS_18expression_pointerIfLb1EEEy[_ZN3kfr4sse215convolve_filterIfE18process_expressionEPfRKNS_18expression_pointerIfLb1EEEy]+0xa6): undefined reference to `kfr::sse2::convolve_filter<float>::process_buffer(float*, float const*, unsigned long long)'
D:\msys64\mingw64\bin\ld: D:\msys64\tmp\min-c3cf3b.o:min.cpp:(.rdata$_ZTVN3kfr4sse215convolve_filterIfEE[_ZTVN3kfr4sse215convolve_filterIfEE]+0x20): undefined reference to `kfr::sse2::convolve_filter<float>::reset()'
D:\msys64\mingw64\bin\ld: D:\msys64\tmp\min-c3cf3b.o:min.cpp:(.rdata$_ZTVN3kfr4sse215convolve_filterIfEE[_ZTVN3kfr4sse215convolve_filterIfEE]+0x28): undefined reference to `kfr::sse2::convolve_filter<float>::process_buffer(float*, float const*, unsigned long long)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Here is the verbose output:

clang version 11.0.0 (https://github.com/msys2/MINGW-packages f5d4dab9b9db65e8b4eff740629c411ea5e21091)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: D:\msys64\mingw64\bin
 "D:\\msys64\\mingw64\\bin\\clang++.exe" -cc1 -triple x86_64-w64-windows-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name min.cpp -mrelocation-model pic mconstructor-aliases -mms-bitfields -munwind-tables -target-cpu x86-64 -debugger-tuning=gdb -v -resource-dir "D:\\msys64\\mingw64\\lib\\clang\\11.0.0" -I D:/msys64/usr/local/include -internal-isystem "D:\em "D:\\msys64\\mingw64\\x86_64-w64-mingw32\\include\\c++\\x86_64-w64-mingw32" -internal-isystem "D:\\msys64\\mingw64\\x86_64-w64-mingw32\\include\\c++\\backward" -internal-isystem "D:\\msys64\\mingw64\\xs64\\mingw64\\x86_64-w64-mingw32\\include\\c++\\10.2.0\\x86_64-w64-mingw32" -internal-isystem "D:\\msys64\\mingw64\\x86_64-w64-mingw32\\include\\c++\\10.2.0\\backward" -internal-isystem "D:\\msys64\\mingwnclude\\c++\\10.2.0\\x86_64-w64-mingw32" -internal-isystem "D:\\msys64\\mingw64\\include\\c++\\10.2.0\\backward" -internal-isystem "D:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\10.2.0\\include\\c++"32\\10.2.0\\include\\c++\\x86_64-w64-mingw32" -internal-isystem "D:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\10.2.0\\include\\c++\\backward" -internal-isystem "D:\\msys64\\mingw64\\lib\\clang\\11.0gw32/sys-root/mingw/include" -internal-isystem "D:\\msys64\\mingw64\\x86_64-w64-mingw32\\include" -internal-isystem "D:\\msys64\\mingw64\\include" -std=c++17 -fdeprecated-macro -fdebug-compilation-dir "D:r-limit 19 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fseh-exceptions -faddrsig -o "D:\\msys64\\tmp\\min-586d16.o" -x c++ min.cpp
clang -cc1 version 11.0.0 based upon LLVM 11.0.0 default target x86_64-w64-windows-gnu
ignoring nonexistent directory "D:\msys64\mingw64\x86_64-w64-mingw32\include\c++"
ignoring nonexistent directory "D:\msys64\mingw64\x86_64-w64-mingw32\include\c++\x86_64-w64-mingw32"
ignoring nonexistent directory "D:\msys64\mingw64\x86_64-w64-mingw32\include\c++\backward"
ignoring nonexistent directory "D:\msys64\mingw64\x86_64-w64-mingw32\include\c++\10.2.0"
ignoring nonexistent directory "D:\msys64\mingw64\x86_64-w64-mingw32\include\c++\10.2.0\x86_64-w64-mingw32"
ignoring nonexistent directory "D:\msys64\mingw64\x86_64-w64-mingw32\include\c++\10.2.0\backward"
ignoring nonexistent directory "D:\msys64\mingw64\lib\gcc\x86_64-w64-mingw32\10.2.0\include\c++"
ignoring nonexistent directory "D:\msys64\mingw64\lib\gcc\x86_64-w64-mingw32\10.2.0\include\c++\x86_64-w64-mingw32"
ignoring nonexistent directory "D:\msys64\mingw64\lib\gcc\x86_64-w64-mingw32\10.2.0\include\c++\backward"
ignoring nonexistent directory "D:\msys64\mingw64\x86_64-w64-mingw32/sys-root/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 D:/msys64/usr/local/include
 D:\msys64\mingw64\include\c++\10.2.0
 D:\msys64\mingw64\include\c++\10.2.0\x86_64-w64-mingw32
 D:\msys64\mingw64\include\c++\10.2.0\backward
 D:\msys64\mingw64\lib\clang\11.0.0\include
 D:\msys64\mingw64\x86_64-w64-mingw32\include
 D:\msys64\mingw64\include
End of search list.
 "D:\\msys64\\mingw64\\bin\\ld" -m i386pep -Bdynamic -o min.exe "D:\\msys64\\mingw64\\x86_64-w64-mingw32\\lib\\crt2.o" "D:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\10.2.0\\crtbegin.o" -LD:/msys64/u10.2.0" "-LD:\\msys64\\mingw64\\x86_64-w64-mingw32\\lib" "-LD:\\msys64\\mingw64\\lib" "-LD:\\msys64\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/lib" "D:\\msys64\\tmp\\min-586d16.o" -lkfr_dft -lkfr_io -lstd -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lkernel32 "D:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\10.2.0\\crtend.o"
D:\msys64\mingw64\bin\ld: D:\msys64\tmp\min-586d16.o:min.cpp:(.text+0x4c6): undefined reference to `kfr::sse2::convolve_filter<float>::convolve_filter(kfr::univector<float const, 0ull> const&, unsigned lo
D:\msys64\mingw64\bin\ld: D:\msys64\tmp\min-586d16.o:min.cpp:(.text$_ZN3kfr4sse215convolve_filterIfE18process_expressionEPfRKNS_18expression_pointerIfLb1EEEy[_ZN3kfr4sse215convolve_filterIfE18process_exprence to `kfr::sse2::convolve_filter<float>::process_buffer(float*, float const*, unsigned long long)'
D:\msys64\mingw64\bin\ld: D:\msys64\tmp\min-586d16.o:min.cpp:(.rdata$_ZTVN3kfr4sse215convolve_filterIfEE[_ZTVN3kfr4sse215convolve_filterIfEE]+0x20): undefined reference to `kfr::sse2::convolve_filter<floa
D:\msys64\mingw64\bin\ld: D:\msys64\tmp\min-586d16.o:min.cpp:(.rdata$_ZTVN3kfr4sse215convolve_filterIfEE[_ZTVN3kfr4sse215convolve_filterIfEE]+0x28): undefined reference to `kfr::sse2::convolve_filter<floa
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Currently very confused because the DFT test was working after compiling KFR. I compiled KFR using -DBUILD_SHARED_LIBS=ON with cmake if that is important. detect_cpu said my processor used AVX2, so I'm not sure why it's trying to use the SSE2 namespace. Some insight into this would be very much appreciated.

nsdrozario commented 3 years ago

I solved it by adding the -mavx2 option when compiling, but that begs the question: how can I make a binary that works with all processor architectures? I can't imagine that I could release a binary of a project that only compiles to avx2.