# Add bin folder of external shared lib to run environment var

**URL:** <https://discourse.cmake.org/t/add-bin-folder-of-external-shared-lib-to-run-environment-var/2257>\
**Category:** Code\
**Created:** [November 27, 2020, 3:50pm UTC](https://discourse.cmake.org/t/add-bin-folder-of-external-shared-lib-to-run-environment-var/2257 "2020-11-27T15:50:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kerim](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/6f9a4e/32.png) [@kerim](https://discourse.cmake.org/u/kerim)\
**Post date:** [November 27, 2020, 3:50pm UTC](https://discourse.cmake.org/t/add-bin-folder-of-external-shared-lib-to-run-environment-var/2257/1 "2020-11-27T15:50:56Z")

</div>

Hi,

I’m learning the basics of CMake.  
The task is to link external shared library and launch in debug/release mode.  
I’m able to successfully link this library and build the project but I’m unable to launch the app because external library is shared and I need to setup the binary folder.

I know I can set this folder from IDE (I use Qt) but I’m looking for a CMake command to set up bin folder of shared linked library.

For example I do:

```
set(PROJLIB_DIR "C:/apps/MSVC_apps_debug/PROJ_7_1_1_Shared")

target_include_directories(
    CMake_Proba
    PRIVATE ${PROJLIB_DIR}/include)

target_link_libraries(
    CMake_Proba
    PRIVATE ${PROJLIB_DIR}/lib/proj_d.lib)

```

This compiles fine. But to run the app I need to specify bin folder of PROJLIB\_DIR.

How can I do that with CMake?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [November 27, 2020, 4:08pm UTC](https://discourse.cmake.org/t/add-bin-folder-of-external-shared-lib-to-run-environment-var/2257/2 "2020-11-27T16:08:43Z")

</div>

There is currently no sense of “runtime usage requirements” which would help with this, sorry. Windows does not support anything like rpaths to make it work either. You’ll just have to modify `PATH` to run the binary (or copy the DLL to be beside your library/executable).

---

<div class="post-metadata">

**Author:** ![kerim](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/6f9a4e/32.png) [@kerim](https://discourse.cmake.org/u/kerim)\
**Post date:** [November 27, 2020, 6:15pm UTC](https://discourse.cmake.org/t/add-bin-folder-of-external-shared-lib-to-run-environment-var/2257/3 "2020-11-27T18:15:34Z")

</div>

I can’t understand a little bit…

Let’s suppose that my project builds one app and one shared lib (app depends on this lib) in the following folders:

- C:\myApp\myApp\myApp.exe
- C:\myApp\myLib\bin
- C:\myApp\myLib\lib
- C:\myApp\myLib\include

The point is that app and created lib are located in different folders. How would look like CMakeLists.txt of myApp? My gut tells me that best practice of CMake uses some CMake features to include the path to binary folder of shared myLib.

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [November 27, 2020, 6:57pm UTC](https://discourse.cmake.org/t/add-bin-folder-of-external-shared-lib-to-run-environment-var/2257/4 "2020-11-27T18:57:41Z")

</div>

You can set [https://cmake.org/cmake/help/latest/variable/CMAKE\_RUNTIME\_OUTPUT\_DIRECTORY.html](https://cmake.org/cmake/help/latest/variable/CMAKE_RUNTIME_OUTPUT_DIRECTORY.html)

---

<div class="post-metadata">

**Author:** ![kerim](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/6f9a4e/32.png) [@kerim](https://discourse.cmake.org/u/kerim)\
**Post date:** [November 27, 2020, 9:14pm UTC](https://discourse.cmake.org/t/add-bin-folder-of-external-shared-lib-to-run-environment-var/2257/5 "2020-11-27T21:14:51Z")

</div>

Thank you for response

I just found some [information about RPATH](https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling) and I feel like many of my questions should be solved after I understand what is written there

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [November 28, 2020, 12:31pm UTC](https://discourse.cmake.org/t/add-bin-folder-of-external-shared-lib-to-run-environment-var/2257/6 "2020-11-28T12:31:07Z")

</div>

Windows has nothing like RPATH, so running from any directory either requires copying or setting PATH environment variable if the output path is not the same.
