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.65k stars 253 forks source link

CMake: Using kfr as dependency leads to linker error for kfr_dft #114

Closed halirutan closed 3 years ago

halirutan commented 3 years ago

I created a minimal example in this repository and used CMake 1.17 and clang 9. I can build kfr itself successfully, but when I try to use it as a dependency in this simple project, I cannot link against kfr_dft. The CMakeLists.txt of the test-project looks like described in the documentation

cmake_minimum_required(VERSION 3.17)
project(KFR_Test)

set(CMAKE_CXX_STANDARD 17)

add_subdirectory(kfr)
add_executable(KFR_Test main.cpp)
target_link_libraries(KFR_Test kfr kfr-dft)

However, running CMake gives a warning for the visibility of the libraries, which might be a hint that they are not exported correctly:

-- The C compiler identification is Clang 9.0.1
-- The CXX compiler identification is Clang 9.0.1
-- Check for working C compiler: /usr/bin/clang-9
-- Check for working C compiler: /usr/bin/clang-9 - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++-9
-- Check for working CXX compiler: /usr/bin/clang++-9 - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Install prefix = /usr/local
-- C++ compiler: Clang 9.0.1 /usr/bin/clang++-9 
-- CMAKE_SYSTEM_PROCESSOR=x86_64
-- X86
-- Detecting native cpu...
-- DETECTED_CPU=avx512
-- CPU_ARCH=avx512
-- kfr_defines=KFR_DFT_NPo2
-- Configuring done
CMake Warning (dev) at kfr/CMakeLists.txt:231 (add_library):
  Policy CMP0063 is not set: Honor visibility properties for all target
  types.  Run "cmake --help-policy CMP0063" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  Target "kfr_dft" of type "STATIC_LIBRARY" has the following visibility
  properties set for CXX:

    CXX_VISIBILITY_PRESET

  For compatibility CMake is not honoring them for this target.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at kfr/CMakeLists.txt:253 (add_library):
  Policy CMP0063 is not set: Honor visibility properties for all target
  types.  Run "cmake --help-policy CMP0063" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  Target "kfr_io" of type "STATIC_LIBRARY" has the following visibility
  properties set for CXX:

    CXX_VISIBILITY_PRESET

  For compatibility CMake is not honoring them for this target.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at kfr/CMakeLists.txt:188 (add_executable):
  Policy CMP0063 is not set: Honor visibility properties for all target
  types.  Run "cmake --help-policy CMP0063" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  Target "detect_cpu" of type "EXECUTABLE" has the following visibility
  properties set for CXX:

    CXX_VISIBILITY_PRESET

  For compatibility CMake is not honoring them for this target.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done

When compiling the test-project, I see the following output:

Scanning dependencies of target KFR_Test
[  8%] Building CXX object kfr/CMakeFiles/kfr_io.dir/include/kfr/io/impl/audiofile-impl.cpp.o
[ 16%] Building CXX object CMakeFiles/KFR_Test.dir/main.cpp.o
[ 25%] Building CXX object kfr/CMakeFiles/detect_cpu.dir/cmake/detect_cpu.cpp.o
[ 33%] Building CXX object kfr/CMakeFiles/kfr_dft.dir/include/kfr/dft/impl/convolution-impl.cpp.o
[ 41%] Building CXX object kfr/CMakeFiles/kfr_dft.dir/include/kfr/dft/impl/dft-impl-f32.cpp.o
[ 50%] Building CXX object kfr/CMakeFiles/kfr_dft.dir/include/kfr/dft/impl/dft-impl-f64.cpp.o
[ 58%] Building CXX object kfr/CMakeFiles/kfr_dft.dir/include/kfr/dft/impl/fft-impl-f32.cpp.o
[ 66%] Building CXX object kfr/CMakeFiles/kfr_dft.dir/include/kfr/dft/impl/fft-impl-f64.cpp.o
[ 75%] Linking CXX executable KFR_Test
/usr/bin/ld: cannot find -lkfr-dft
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/KFR_Test.dir/build.make:104: KFR_Test] Error 1
make[1]: *** [CMakeFiles/Makefile2:121: CMakeFiles/KFR_Test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 83%] Linking CXX executable detect_cpu
[ 83%] Built target detect_cpu
[ 91%] Linking CXX static library libkfr_io.a
[ 91%] Built target kfr_io
[100%] Linking CXX static library libkfr_dft.a
[100%] Built target kfr_dft
make: *** [Makefile:150: all] Error 2

Finally, what I eventually want is to not include the kfr sources at all in my project and use CMake's FetchContent_Declare to automatically retrieve the release of kfr like I do for other libraries.

ehaubold commented 3 years ago

I didn't have a too detailed look, but Linking CXX static library libkfr_dft.a and /usr/bin/ld: cannot find -lkfr-dft suggests, that you need to change the dash in your cmakelists to a underscore

halirutan commented 3 years ago

That happens, when you expect the error to be in the cmake config and overlook a simple dash for 2 hours..

image