Add bin folder of external shared lib to run environment var


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")

    PRIVATE ${PROJLIB_DIR}/include)

    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?

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).

1 Like

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.

You can set

Thank you for response

I just found some information about RPATH and I feel like many of my questions should be solved after I understand what is written there

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.

1 Like