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.62k stars 248 forks source link

Build failed CAPI on Docker ubuntu22 with Clang #209

Closed xkzl closed 5 months ago

xkzl commented 5 months ago

Hello,

I tried to compile KFR v6 branch with CAPI option enabled:

> cmake ../src -DKFR_ENABLE_CAPI_BUILD=ON -DCMAKE_CXX_COMPILER=clang++
-- The CXX compiler identification is Clang 14.0.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting target architecture
-- Default CPU architecture for KFR is sse2 (set KFR_ARCH to override)
-- Runtime dispatch is enabled for architectures: sse2;sse41;avx;avx2;avx512 (set KFR_ARCHS to change, set KFR_ENABLE_MULTIARCH=OFF to disable)
-- Configuring done
-- Generating done

It seems in this very specific case I am facing the following issue:

[100%] Linking CXX shared library libkfr_capi.so
/usr/bin/ld: /opt/kfr/build/src/dsp/libkfr_dsp_sse2.a(biquad.cpp.o): warning: relocation against `_ZN3kfr17expression_vtableIdLm1EE17static_begin_passINS_4sse218expression_biquadsILm8EdNS_22expression_placeholderIdLm1ELm0EEEEEEEvPvNS_5shapeILm1EEESA_' in read-only section `.text._ZN3kfr17expression_vtableIdLm1EEC2INS_4sse218expression_biquadsILm8EdNS_22expression_placeholderIdLm1ELm0EEEEEEEN6cometa7ctype_tIT_EE[_ZN3kfr17expression_vtableIdLm1EEC2INS_4sse218expression_biquadsILm8EdNS_22expression_placeholderIdLm1ELm0EEEEEEEN6cometa7ctype_tIT_EE]'
/usr/bin/ld: /opt/kfr/build/src/dft/libkfr_dft_sse2.a(convolution-impl.cpp.o): relocation R_X86_64_PC32 against symbol `_ZGVZN3kfr4sse214dft_cache_implILi0EE8instanceEvE5cache' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/capi/CMakeFiles/kfr_capi.dir/build.make:107: src/capi/libkfr_capi.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:490: src/capi/CMakeFiles/kfr_capi.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
error building image: error building stage: failed to execute command: waiting for process to exit: exit status 2

Would you have any suggestion how to fix ? At this time I can disable CAPI and it works, but I would like to enable it .

dancazarin commented 5 months ago

Hello,

On linux/macOS KFR C API requires passing -DCMAKE_POSITION_INDEPENDENT_CODE=ON to cmake. You can see examples of working configurations for various platforms here: https://github.com/kfrlib/kfr/blob/v6/.github/workflows/build.yml