Cannot link with UNKNOWN IMPORTED library if GLOBAL was used
IMPORTED library which is neither marked as
SHARED but instead as
UNKNOWN can be linked to another target via
target_link_libraries (in the same scope).
... add_library( ImportedLib::NonGlobal UNKNOWN IMPORTED ) ... add_executable( AnotherTarget main.cpp ) target_link_library( AnotherTarget PRIVATE ImportedLib::NonGlobal )
This works fine unless one also used
GLOBAL when creating the
... add_library( ImportedLib::Global UNKNOWN IMPORTED GLOBAL) ... add_executable( AnotherTarget main.cpp ) target_link_library( AnotherTarget PRIVATE ImportedLib::Global )
CMake Error at CMakeLists.txt:10 (target_link_libraries): Target "ImportedLib::Global" of type UNKNOWN_LIBRARY may not be linked into another target. One may link only to STATIC or SHARED libraries, or to executables with the ENABLE_EXPORTS property set.
It does not make sense that adding the
GLOBAL keyword prevents successful linking while without it works just fine.