IMPORTED_IMPLIB not set for imported target

I build a opencv library and use it on vs2019.
What is the error ?
the folder ‘opencv\x64\vc16\lib’ that I include have the opencv_reg455d.lib

CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_reg" configuration
  "RelWithDebInfo".
-- "C:/Program Files (x86)/WiX Toolset v3.11/bin/candle.exe" D:/TEST/cmake/deb/windows/bundle.wxs -ext WixBalExtension -ext WixUtilExtension -nologo
"C:/Program Files (x86)/WiX Toolset v3.11/bin/light.exe" D:/TEST/build-debug/bundle.wixobj -o 123.exe -ext WixBalExtension -ext WixUtilExtension -nologo
-- Configuring done
CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_rapid" configuration
  "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_reg" configuration
  "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_rgbd" configuration
  "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_saliency" configuration
  "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_shape" configuration
  "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_stereo" configuration
  "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_structured_light"
  configuration "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_superres" configuration
  "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_surface_matching"
  configuration "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_text" configuration
  "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_tracking" configuration
  "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_videostab"
  configuration "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_wechat_qrcode"
  configuration "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_xfeatures2d"
  configuration "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_ximgproc" configuration
  "RelWithDebInfo".


CMake Error in CMakeLists.txt:
  IMPORTED_IMPLIB not set for imported target "opencv_xobjdetect"
  configuration "RelWithDebInfo".

You’ll need to use MAP_IMPORTED_CONFIG_<CONFIG> to tell CMake that you want to use a different config for OpenCV.

I replace ${OpenCV_LIBRARIES} with sc_opencv.
I try to set ${sc_opencv} with MAP_IMPORTED_CONFIG_<CONFIG>
But ${sc_opencv} is empty with cmake message(${sc_opencv})

cmake_minimum_required (VERSION 3.8)

project(test)
find_package(OpenCV CONFIG REQUIRED)
add_executable (test "main.cpp")
add_library(sc_opencv
        STATIC
        IMPORTED)
set_property(
  TARGET sc_opencv APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG
  )
set_target_properties(sc_opencv PROPERTIES
  IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
  IMPORTED_LOCATION_DEBUG "D:/TEST/debug/opencv/x64/vc16/lib"
  )
target_include_directories(test PUBLIC
	${OpenCV_INCLUDE_DIRS}
)
target_link_libraries(test PUBLIC
	${sc_opencv}
)

Here is the ${OpenCV_LIBRARIES}

opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;

This is not how you set a location for an IMPORTED target. Since it is a SHARED library, you must set IMPORTED_LOCATION_DEBUG to the DLL path and IMPORTED_IMPLIB_DEBUG to the .lib path (for the linker).

1 Like

Hi @alice,

have you found some solution? I have the same problem even if I use MAP_IMPORTED_CONFIG_ as suggested.

Thanks

Since nothing is marked as a solution, and there are still questions posted.

I’ve recently stumbled upon a similar(?) problem, although with a different library (but also on Windows). Following this nice example from documentation, importing instructions would be something like this (as Ben said, both IMPORTED_LOCATION and IMPORTED_IMPLIB need to be set):

# variables that my FindSome.cmake module is discovering:
# - SOME_LIBRARY_DLL: /path/to/dependencies/bin/some.dll
# - SOME_LIBRARY: /path/to/dependencies/lib/some.lib
# - SOME_INCLUDE_DIRS: /path/to/dependencies/include

add_library(SOME::LIBRARY SHARED IMPORTED) # SHARED, since it's a DLL
# Release configuration properties
set_property(TARGET SOME::LIBRARY
    APPEND PROPERTY
        IMPORTED_CONFIGURATIONS RELEASE
)
set_target_properties(SOME::LIBRARY PROPERTIES
    IMPORTED_LOCATION_RELEASE "${SOME_LIBRARY_DLL}"
    IMPORTED_IMPLIB_RELEASE "${SOME_LIBRARY}"
)
# Debug configuration properties
set_property(TARGET SOME::LIBRARY
    APPEND PROPERTY
        IMPORTED_CONFIGURATIONS DEBUG
)
set_target_properties(SOME::LIBRARY PROPERTIES
    IMPORTED_LOCATION_DEBUG "${SOME_LIBRARY_DLL}"
    IMPORTED_IMPLIB_DEBUG "${SOME_LIBRARY}"
)
# common properties
set_target_properties(SOME::LIBRARY PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES "${SOME_INCLUDE_DIRS}"
)
# mapping for exotic configurations (doesn't seem to be needed)
# set_target_properties(SOME::LIBRARY PROPERTIES
#     MAP_IMPORTED_CONFIG_MINSIZEREL Release
#     MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
# )

From which I realized that all of those can be reduced to just the following:

add_library(SOME::LIBRARY SHARED IMPORTED)
set_target_properties(SOME::LIBRARY PROPERTIES
    IMPORTED_LOCATION "${SOME_LIBRARY_DLL}"
    IMPORTED_IMPLIB "${SOME_LIBRARY}"
    INTERFACE_INCLUDE_DIRECTORIES "${SOME_INCLUDE_DIRS}"
)

Either way, my project now configures equally fine with either Release, Debug or RelWithDebInfo:

$ cd /path/to/project
$ mkdir build && cd $_
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DCMAKE_PREFIX_PATH="/path/to/dependencies" \
    ..

Although later in another project this second “reduced” variant didn’t work for some reason (most probably because there was already CMAKE_MAP_IMPORTED_CONFIG_* mapping set in the main project), so I had to use the first longer variant, and that one did work.

Now, how to deal with this in cases like OpenCV here, when there is more than one library (opencv_rapid, opencv_reg, opencv_rgbd, etc) - that I don’t know. So far it looks like one would need to create a target for each one of them and set IMPORTED_LOCATION / IMPORTED_IMPLIB for those targets accordingly. It seems to me that this is something OpenCVConfig.cmake should do, actually, since OpenCV is discovered in CONFIG mode over there.

Regarding mapping configurations, perhaps this high caliber would work too:

set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL Release)
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release)