# Missing imported target

**URL:** <https://discourse.cmake.org/t/missing-imported-target/8163>\
**Category:** Code\
**Created:** [May 19, 2023, 9:08am UTC](https://discourse.cmake.org/t/missing-imported-target/8163 "2023-05-19T09:08:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![robiwano](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robiwano/32/1027_2.png) [@robiwano](https://discourse.cmake.org/u/robiwano)\
**Post date:** [May 19, 2023, 9:08am UTC](https://discourse.cmake.org/t/missing-imported-target/8163/1 "2023-05-19T09:08:29Z")

</div>

I have a folder structure like so:  
/build  
/src  
/import  
where /import contains /include and /lib folder for an imported target. /import also has a CMakeLists.txt file with following content:

```auto
add_library(my_import_target SHARED IMPORTED)
target_include_directories(my_import_target INTERFACE include)
set_target_properties(my_import_target
  PROPERTIES
  IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lib/my_import_target.so"
)
if (TARGET my_import_target)
  message("Yay!")
endif()

```

Then in the /src/CMakeLists.txt file:

```auto
add_subdirectory(../import imported)
if (NOT TARGET my_import_target)
  message(FATAL_ERROR "Target not found")
endif()

```

The last test “fails”, i.e. my\_import\_target is not defined even though add\_subdirectory was called just before it. What is wrong?

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [May 19, 2023, 10:16am UTC](https://discourse.cmake.org/t/missing-imported-target/8163/2 "2023-05-19T10:16:33Z")

</div>

By default, imported targets do not have a global scope. To solve your problem, add keyword `GLOBAL`:

```cmake
add_library(my_import_target SHARED IMPORTED GLOBAL)

```
