# cmake 3.17.0 generates target-NOTFOUND for configured target

**URL:** <https://discourse.cmake.org/t/cmake-3-17-0-generates-target-notfound-for-configured-target/1642>\
**Category:** Code\
**Tags:** os:linux, gen:makefiles\
**Created:** [July 29, 2020, 6:02pm UTC](https://discourse.cmake.org/t/cmake-3-17-0-generates-target-notfound-for-configured-target/1642 "2020-07-29T18:02:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yisseamake](https://discourse.cmake.org/user_avatar/discourse.cmake.org/yisseamake/32/897_2.png) [@yisseamake](https://discourse.cmake.org/u/yisseamake)\
**Post date:** [July 29, 2020, 6:02pm UTC](https://discourse.cmake.org/t/cmake-3-17-0-generates-target-notfound-for-configured-target/1642/1 "2020-07-29T18:02:26Z")

</div>

Could you please advise what causes cmake to fail finding existing imported library target when generating build.make \_EXTERNAL\_OBJECTS list.  
cmake generates file

```auto
./build/mingw64/myprjsrc/CMakeFiles/myshared.dir/build.make

```

with target shown as NOTFOUND:

```auto
myshared_EXTERNAL_OBJECTS =
     myprjsrc/libmyshared.dll: myprjsrc/CMakeFiles/myshared.dir/build.make
     myprjsrc/libmyshared.dll: **qq-NOTFOUND**

```

Despite that configuiration-generation was successful and target qq was configured - added, had valid target properties, target\_link\_libraries linked it successfully and had valid file location and type.  
sample code snippet is below.  
Note: this build is running on linux and uses mingw64 build chain to cross compile dll to run on Windows. The same cmake code is used for cross compiling to another linux and works fine with .so. However library property IMPORTED\_LOCATION ${LIBQQ\_LIBRARY} .dll.a or .a file, doesn’t fix the problem.

_FindQQ.cmake_

```cmake
set(LIBQQ_LIBRARY "${LIBQQ_LIBRARY_DIRS}/lib${QQ_LIB_NAME}.dll" CACHE STRING "Link libraries ..." FORCE )
set(qqShared "qq" CACHE STRING "QQ target name")
# log confirms library target added at ${LIBQQ_LIBRARY} in ${LIBQQ_LIBRARY_DIRS}
if(NOT TARGET ${qqShared} )
  add_library( ${qqShared} SHARED IMPORTED GLOBAL ) # <---- NOTE
  set_target_properties( ${qqShared} PROPERTIES IMPORTED_LOCATION ${LIBQQ_LIBRARY} )
  target_include_directories( ${qqShared}
        INTERFACE
             ${LIBQQ_INCLUDE_DIRS}
  )
 
  message(STATUS "<< ____ FindQQ cmake Added! Lib '${qqShared}' LIBQQ_LIBRARY '${LIBQQ_LIBRARY}' LIBQQ_LIBRARY_DIRS '${LIBQQ_LIBRARY_DIRS}' ")

else()
  message(....has been already added ...)
endif()

#check shows target exists
if(TARGET ${qqShared})
 ..

```

_CMakeLists.txt_

```cmake
#finds lib and adds target lib ${qqShared}
set(QQ_LIB_NAME qq CACHE STRING "QQ base library name" FORCE ) # used by FindQQ.cmake
find_package(QQ)

#check ${qqShared} target exists before and after target_link_libraries
if(TARGET ${qqShared}) ...
# link top lib myshared with extrernal dependencies
target_link_libraries(myshared
    PUBLIC
        ${qqShared}
      ...
    PRIVATE
    ...
)

#DEBUG log file check shows correct path ${LIBQQ_LIBRARY_DIRS}/lib${QQ_LIB_NAME}.dll :
   get_target_property(include_path_defs ${qqShared} LOCATION )
   file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${qqShared}_target_prop_loc.txt ${include_path_defs})

```

---

<div class="post-metadata">

**Author:** ![yisseamake](https://discourse.cmake.org/user_avatar/discourse.cmake.org/yisseamake/32/897_2.png) [@yisseamake](https://discourse.cmake.org/u/yisseamake)\
**Post date:** [July 30, 2020, 7:44pm UTC](https://discourse.cmake.org/t/cmake-3-17-0-generates-target-notfound-for-configured-target/1642/2 "2020-07-30T19:44:34Z")

</div>

I worked around this problem by changing library type to STATIC from SHARED:

```cmake
add_library( ${qqShared} STATIC IMPORTED GLOBAL )

```

However I need to build dll. there should be no limitation in cmake preventing crosscompile dll. At minimum cmake should generate error during generation time since it is not able to generate build.make and linklibs.rsp files correctly from the target properties. This is because target properties are valid and reflect all target associated commands: INTERFACE\_INCLUDE\_DIRECTORIES, IMPORTED\_LOCATION, etc… were set correctly , target was configured but cmake generated files are invalid with no errors. Is it a bug?

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [August 4, 2020, 1:33pm UTC](https://discourse.cmake.org/t/cmake-3-17-0-generates-target-notfound-for-configured-target/1642/3 "2020-08-04T13:33:05Z")

</div>

For an imported shared library on Windows, the [`IMPORTED_IMPLIB`](https://cmake.org/cmake/help/v3.18/prop_tgt/IMPORTED_IMPLIB.html) property needs to be set with the location of the DLL import library. I’ve opened [CMake MR 5096](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5096) to mention this in the `add_library` documentation on imported targets.
