# What is the use of property IMPORTED\_LOCATION on DLL platforms?

**URL:** <https://discourse.cmake.org/t/what-is-the-use-of-property-imported-location-on-dll-platforms/2069>\
**Category:** Code\
**Created:** [October 25, 2020, 2:33pm UTC](https://discourse.cmake.org/t/what-is-the-use-of-property-imported-location-on-dll-platforms/2069 "2020-10-25T14:33:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shane\_Dev](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shane_dev/32/841_2.png) [@Shane\_Dev](https://discourse.cmake.org/u/Shane_Dev)\
**Post date:** [October 25, 2020, 2:33pm UTC](https://discourse.cmake.org/t/what-is-the-use-of-property-imported-location-on-dll-platforms/2069/1 "2020-10-25T14:33:17Z")

</div>

Hello,

According to [the docs](https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_LOCATION.html?highlight=imported_location), `IMPORTED_LOCATION` should be set to the `.dll` part of the library. I have found that it is [not necessary](https://github.com/shanemcandrewai/aten_libtorch/blob/master/CMakeLists.txt#L58-L59). However the DLL does need to be in an appropriate location such as `${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}` at runtime. In that case, why are we advised to set `IMPORTED_LOCATION`?

---

<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:** [October 25, 2020, 2:51pm UTC](https://discourse.cmake.org/t/what-is-the-use-of-property-imported-location-on-dll-platforms/2069/2 "2020-10-25T14:51:48Z")

</div>

This is for `IMPORTED` targets, i.e. targets not built by current `CMake` project. So binaries are supposed to be elsewhere than current `CMake` filetree.

In your case, by a side effect, it works because you had copied the library inside `CMake` filetree.

But it seems more reasonable to set `IMPORTED_LOCATION` and **not** copied the library.

---

<div class="post-metadata">

**Author:** ![Shane\_Dev](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shane_dev/32/841_2.png) [@Shane\_Dev](https://discourse.cmake.org/u/Shane_Dev)\
**Post date:** [October 25, 2020, 7:12pm UTC](https://discourse.cmake.org/t/what-is-the-use-of-property-imported-location-on-dll-platforms/2069/3 "2020-10-25T19:12:55Z")

</div>

Hi Marc,

I tried deleting the DLLs from `${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}` and [the code which copied them from the imported library](https://github.com/shanemcandrewai/aten_libtorch/blob/master/CMakeLists.txt#L52-L57) and then set the `IMPORTED_LOCATION` to the DLLs from the imported library, see [the new script](https://github.com/shanemcandrewai/aten_libtorch/blob/IMPORTED_LOCATION/CMakeLists.txt#L52-L53). It builds successfully but when I run the executable `aten_libtorch.exe`, I receive pop out System Error messages - The code execution cannot proceed because c10.dll/torch\_cpu was not found. So what is the benefit of setting `IMPORTED_LOCATION`?
