How to fix ninja error when linking to DLLs in CMake on Windows?

48 Views Asked by At

I'm trying to link 30+ DLLs from Magick++ to my app in CMake. I've tried adapting a static linking code I've written before and got to this:

file(GLOB files ${CMAKE_SOURCE_DIR}/Dependencies/Magick/lib/*.dll)
foreach(filePath ${files})
    list(APPEND magick_libs_list somelib_release_${i})

    add_library(somelib_release_${i} SHARED IMPORTED)
    set_target_properties(somelib_release_${i} PROPERTIES IMPORTED_LOCATION ${filePath})

    MATH(EXPR i "${i}+1")
endforeach()

target_link_libraries(MyApp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${magick_libs_list})
include_directories(${CMAKE_SOURCE_DIR}/Dependencies/Magick/include)

However I get this error:

ninja: error: 'somelib_release_8-NOTFOUND', needed by 'CMakeFiles/MyApp_autogen_timestamp_deps', missing and no known rule to make it
22:48:23: The process "C:\Qt\Tools\CMake_64\bin\cmake.exe" exited with code 1.
Error while building/deploying project MyApp (kit: Desktop Qt 6.6.1 MSVC2019 64bit)
When executing step "Build"

How can I make it find the DLLs and build the project?

0

There are 0 best solutions below