# IMPORTED\_IMPLIB not set for imported target

**URL:** https://discourse.cmake.org/t/imported-implib-not-set-for-imported-target/5398
**Category:** Usage
**Tags:** os:windows
**Created:** [April 7, 2022, 2:05pm UTC](https://discourse.cmake.org/t/imported-implib-not-set-for-imported-target/5398 "2022-04-07T14:05:04Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [April 7, 2022, 2:05pm UTC](https://discourse.cmake.org/t/imported-implib-not-set-for-imported-target/5398/1 "2022-04-07T14:05:04Z")

</div>

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`

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

```

```auto
-- "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".

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 9, 2022, 12:51pm UTC](https://discourse.cmake.org/t/imported-implib-not-set-for-imported-target/5398/2 "2022-04-09T12:51:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [April 10, 2022, 7:50am UTC](https://discourse.cmake.org/t/imported-implib-not-set-for-imported-target/5398/3 "2022-04-10T07:50:51Z")

</div>

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})

```auto
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}

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

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 12, 2022, 12:03pm UTC](https://discourse.cmake.org/t/imported-implib-not-set-for-imported-target/5398/4 "2022-04-12T12:03:11Z")

</div>

> [@alice](#):
>
> ```auto
> set_target_properties(sc_opencv PROPERTIES
> IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
> IMPORTED_LOCATION_DEBUG "D:/TEST/debug/opencv/x64/vc16/lib"
> )
> 
> ```

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).

---

<div class="post-metadata">

### Author: ![eric](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/e/898d66/32.png) [@eric](https://discourse.cmake.org/u/eric)
#### Post date: [December 30, 2022, 5:00pm UTC](https://discourse.cmake.org/t/imported-implib-not-set-for-imported-target/5398/5 "2022-12-30T17:00:10Z")

</div>

Hi @alice,

have you found some solution? I have the same problem even if I use MAP\_IMPORTED\_CONFIG\_ as suggested.

Thanks

---

<div class="post-metadata">

### Author: ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)
#### Post date: [November 24, 2023, 7:35pm UTC](https://discourse.cmake.org/t/imported-implib-not-set-for-imported-target/5398/6 "2023-11-24T19:35:21Z")

</div>

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](https://cmake.org/cmake/help/latest/prop_tgt/MAP_IMPORTED_CONFIG_CONFIG.html#example) from documentation, importing instructions would be something like this (_as Ben said, both `IMPORTED_LOCATION` and `IMPORTED_IMPLIB` need to be set_):

```cmake
# 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:

```cmake
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`:

```sh
$ 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:

```cmake
set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL Release)
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release)

```

---

<div class="post-metadata">

### Author: ![qw-code](https://discourse.cmake.org/user_avatar/discourse.cmake.org/qw-code/32/5841_2.png) [@qw-code](https://discourse.cmake.org/u/qw-code)
#### Post date: [October 2, 2025, 3:28pm UTC](https://discourse.cmake.org/t/imported-implib-not-set-for-imported-target/5398/7 "2025-10-02T15:28:27Z")

</div>

you should use release mode to configure opencv not with RelWithDebInfo, because that opencv doesn’t provide RelWithDebInfo mode officially.
