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

Unsure about compilation kfr_dft.lib #228

Closed VUT246843 closed 1 month ago

VUT246843 commented 1 month ago

I'm new to cmake and confused. Cloned repo and have the following:

add_subdirectory("C:/kfr" kfr-build-dir)

target_link_libraries(AudioP PUBLIC kfr)
target_link_libraries(AudioP PUBLIC kfr_dsp)
target_link_libraries(AudioP PUBLIC kfr_dft)

It compiles and I was able to use univectors, but the kfr_dft is causing: LINK : fatal error LNK1104: cannot open file 'kfr_dft.lib' Am I supposed to setup clang and all the tools and prebuild the code like in 'Build and install KFR (recommended)'? windows

VUT246843 commented 1 month ago

Installed correct LLVM win64 and downloaded clang.exe. Built the source using clang/ninja into a new folder. These commands have explicit paths, env. paths are another way.

cd C:\kfr
cmake -B build-release -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="C:\kfr\install" -DCMAKE_CXX_COMPILER="C:\LLVM\bin\clang++.exe" -DCMAKE_MAKE_PROGRAM="C:\LLVM\ninja-win\ninja.exe"
C:\LLVM\ninja-win\ninja.exe -C build-release install
cmake -B build-debug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="C:\kfr\install" -DCMAKE_CXX_COMPILER="C:\LLVM\bin\clang++.exe" -DCMAKE_MAKE_PROGRAM="C:\LLVM\ninja-win\ninja.exe"
C:\LLVM\ninja-win\ninja.exe -C build-debug install

In cmake I tried many variants of both find_package and add_subdirectory imports, changed compiler to clang. It is either missing base.hpp or stdc++.lib pthread.lib or whatever. Moreover, I tried https://github.com/kfrlib/kfr/issues/114 as

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)

Which throws fatal error LNK1104: cannot open file 'kfr_dft.lib' again.

dancazarin commented 1 month ago

Could you attach the logs of cmake invocation?

CMakeCache.txt would be helpful too (it contains build settings and build tools paths)

VUT246843 commented 1 month ago

This is from the minimal example. logs.zip

dancazarin commented 1 month ago

This is from your CMakeCache.txt

//CXX compiler
CMAKE_CXX_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe

This means that you didn't switch compiler to clang or this was not successful. Please refer to the cmake documentation to learn how to set compiler path correctly.

KFR works with Visual Studio but DFT is not available unless you use clang compiler.

dancazarin commented 1 month ago

Please attach the logs of the Configure step of cmake. Example from Clion:

cl_cmaketutorial_toolwindow
VUT246843 commented 1 month ago

Changed to clang-cl in toolchains and it builds now. Will test on my own code. success.txt

VUT246843 commented 1 month ago

Thanks, this saved me a lot of cmake headache. I suggest the two ways in docs be more clearly separated and to add a comment that the pre-build is not required (for the former?) Here is my cmake config with JUCE + KFR for others' reference.

cmake_minimum_required(...)
project(PROJECT_NAME VERSION 0.0.1)
add_subdirectory("C:/JUCE" JUCE)
add_subdirectory(kfr)

juce_add_plugin(TARGET-NAME
...)

target_sources(TARGET-NAME
        PRIVATE
        PluginEditor.cpp
        PluginProcessor.cpp)

target_compile_definitions(TARGET-NAME
...)

target_link_libraries(TARGET-NAME
        PRIVATE
        juce::juce_audio_utils
        juce::juce_dsp
        PUBLIC
        juce::juce_recommended_config_flags
        juce::juce_recommended_lto_flags
        juce::juce_recommended_warning_flags
)
target_link_libraries(TARGET-NAME PUBLIC kfr kfr_dsp kfr_dft)

If you don't want to add anything, the issue can be closed.

VUT246843 commented 1 month ago

I will add for those facing the issue with LLVM, clang-cl, ninja: ninja: error: FindFirstFileExA(note: including file... I finally solved it by clearing build files and using NMAKE instead of ninja.