# IMPORTED\_LOCATION is incorrect for OpenSSL::SSL and OpenSSL::Crypto

**URL:** https://discourse.cmake.org/t/imported-location-is-incorrect-for-openssl-ssl-and-openssl-crypto/8040
**Category:** Code
**Tags:** os:windows
**Created:** [May 3, 2023, 1:43am UTC](https://discourse.cmake.org/t/imported-location-is-incorrect-for-openssl-ssl-and-openssl-crypto/8040 "2023-05-03T01:43:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)
#### Post date: [May 3, 2023, 1:43am UTC](https://discourse.cmake.org/t/imported-location-is-incorrect-for-openssl-ssl-and-openssl-crypto/8040/1 "2023-05-03T01:43:53Z")

</div>

### Problem Description

I installed OpenSSL using the binaries installer provided by [ShiningLight.OpenSSL](https://slproweb.com/products/Win32OpenSSL.html) on Windows. And here is its install location:

```auto
C:\Program Files\OpenSSL-Win64

```

However, I found that the imported targets defined by `FindOpenSSL` built-in module don’t have correct `IMPORTED_LOCATION` or `IMPORTED_LOCATION_<CONFIG>` specified with this version of OpenSSL installed. I used `CMakePrintHelpers` module to check its values:

```cmake
include(CMakePrintHelpers)
cmake_print_properties(
    TARGETS 
        OpenSSL::SSL
        OpenSSL::Crypto
    PROPERTIES
        IMPORTED_LOCATION
        IMPORTED_LOCATION_DEBUG
        IMPORTED_LOCATION_RELEASE
)

```

The result turns out that:

```auto
-- 
 Properties for TARGET OpenSSL::SSL:
   OpenSSL::SSL.IMPORTED_LOCATION = <NOTFOUND>
   OpenSSL::SSL.IMPORTED_LOCATION_DEBUG = "C:/Program Files/OpenSSL-Win64/lib/VC/libssl64MDd.lib"
   OpenSSL::SSL.IMPORTED_LOCATION_RELEASE = "C:/Program Files/OpenSSL-Win64/lib/VC/libssl64MD.lib"
 Properties for TARGET OpenSSL::Crypto:
   OpenSSL::Crypto.IMPORTED_LOCATION = <NOTFOUND>
   OpenSSL::Crypto.IMPORTED_LOCATION_DEBUG = "C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MDd.lib"
   OpenSSL::Crypto.IMPORTED_LOCATION_RELEASE = "C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MD.lib"

```

As we can see:

- `IMPORTED_LOCATION` is empty
- `IMPORTED_LOCATION_<CONFIG>` is specified with `*.lib` instead of `*.dll`

In my opinions, these two variables should be populated with:

- OpenSSL::SSL: `C:\Program Files\OpenSSL-Win64\bin\libssl-3-x64.dll`
- OpenSSL::Crypto: `C:\Program Files\OpenSSL-Win64\bin\libcrypto-3-x64.dll`

respectively.

Therefore, I think this is why I failed to use [`$<TARGET_RUNTIME_DLLS:tgt>`](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#genex:TARGET_RUNTIME_DLLS) regex to copy the runtime dependencies of my executable linked with `OpenSSL::SSL` and `OpenSSL::Crypto`:

```cmake
if (WIN32)
    add_custom_command(
        TARGET ${target_name} POST_BUILD
        COMMAND 
            "${CMAKE_COMMAND}" -E copy -t
            "$<TARGET_RUNTIME_DLLS:${target_name}>"
            "$<TARGET_FILE_DIR:${target_name}>"
        COMMAND_EXPAND_LISTS
    )
endif ()

```

And the following is the error message caused by not having `libcrypto-3-x64.dll` and `libssl-3-x64.dll` in the [`$<TARGET_FILE_DIR:tgt>`](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#genex:TARGET_FILE_DIR) directory:

 ![image](https://discourse.cmake.org/uploads/default/original/2X/a/af65f1f56f7fa640527ee19efcedbb8650cec589.png)

### Versions and Environments

- OS version: `Windows 11`
- CMake version: `3.26.3`
- OpenSSL version: `3.0.8`

---

<div class="post-metadata">

### Author: ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)
#### Post date: [May 3, 2023, 1:46am UTC](https://discourse.cmake.org/t/imported-location-is-incorrect-for-openssl-ssl-and-openssl-crypto/8040/2 "2023-05-03T01:46:42Z")

</div>

cc: @brad.king @craig.scott

---

<div class="post-metadata">

### Author: ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)
#### Post date: [May 3, 2023, 10:14am UTC](https://discourse.cmake.org/t/imported-location-is-incorrect-for-openssl-ssl-and-openssl-crypto/8040/3 "2023-05-03T10:14:49Z")

</div>

The subsequent problem I encountered is that:

I link my executable with the `libevent::openssl` module of [libevent](https://github.com/libevent/libevent) library dynamically. And its runtime dependency `event_openssld.dll` is indeed copied successfully.

However, `event_openssld.dll` depends on [OpenSSL’s runtime dependencies](https://github.com/libevent/libevent/blob/release-2.1.12-stable/CMakeLists.txt#L959), `libcrypto-3-x64.dll` and `libssl-3-x64.dll`. Therefore, the error messages that the program cannot find those OpenSSL’s runtime dependencies appear.

![image](https://discourse.cmake.org/uploads/default/original/2X/5/5d0376348f53854e5df5e1181569115ea6af0be5.png)

---

<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: [May 3, 2023, 1:23pm UTC](https://discourse.cmake.org/t/imported-location-is-incorrect-for-openssl-ssl-and-openssl-crypto/8040/4 "2023-05-03T13:23:04Z")

</div>

FindOpenSSL’s imported targets, like those of all find modules, are meant for use during the build. When finding shared libraries on Windows, only the `.lib` import library part is needed for linking. We don’t currently try to find the `.dll` part at all, let alone populate their location in imported targets. The documentation of `$<TARGET_RUNTIME_DLLS>` specifically mentions this.

There are some open issues about adding `.dll` information to find modules and tracking runtime dependencies more explicitly.

---

<div class="post-metadata">

### Author: ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)
#### Post date: [June 18, 2023, 1:44pm UTC](https://discourse.cmake.org/t/imported-location-is-incorrect-for-openssl-ssl-and-openssl-crypto/8040/5 "2023-06-18T13:44:35Z")

</div>

@brad.king

So except for **“adding `bin` path to `PATH` env”** and **“copying DLLs manually to runtime output directory”** , what is the alternative/recommanded way to deal with the situation using dynamic linkage libraries of OpenSSL?
