title: Building of executable and shared library with cmake, runtimelinker does not find dll
body: <p>I am working with gcc(cygwin), gnu make, windows 7 and cmake.</p>
  
  <p>my cmake testprojekt has the following structure</p>
  
  <pre><code>rootdir
  |-- App
  |   |-- app.cpp
  |   +-- CMakeLists.txt
  |-- Lib
  |   |-- lib.cpp
  |   |-- CMakeLists.txt
  |-- MakeFileProject
  + CMakeLists.txt
  </code></pre>
  
  <p>rootdir/App/app.cpp:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include&lt;string&gt;
  void printThemMessageToScreen(std::string input);//prototype
  int main(int argc,char **argv){
   printThemMessageToScreen("this will be displayed by our lib");
   return 0;
  }
  </code></pre>
  
  <p>rootdir/Lib/lib.cpp:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  
  void printThemMessageToScreen(std::string input){
   std::cout&lt;&lt;input;
  }
  </code></pre>
  
  <p>rootdir/CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.6)
  project(TestProject)
  
  add_subdirectory(App)
  add_subdirectory(Lib)
  </code></pre>
  
  <p>rootdir/Lib/CMakeLists.txt:</p>
  
  <pre><code>add_library(Lib SHARED lib.cpp)
  </code></pre>
  
  <p>rootdir/App/CMakeLists.txt:</p>
  
  <pre><code># Make sure the compiler can find include files from our Lib library. 
  include_directories (${LIB_SOURCE_DIR}/Lib) 
  
  # Make sure the linker can find the Lib library once it is built. 
  link_directories (${LIB_BINARY_DIR}/Lib) 
  
  # Add executable called "TestProjectExecutable" that is built from the source files 
  add_executable (TestProjectExecutable app.cpp) 
  
  # Link the executable to the lib library. 
  target_link_libraries (TestProjectExecutable Lib) 
  </code></pre>
  
  <p>Now, when i run cmake and make, everything will get generated &amp; built with no errors, but when i try to execute the binary, it will fail because the library which was generated could not be found. </p>
  
  <p>BUT: when i copy the lib dll into the same directory like the app exe, it will get executed!</p>
  
  <p>also: if i configure the library to be static, it will also execute.</p>
  
  <p>how to tell the runtime linker where to look for my dll?</p>
  
  <h2>UPDATE:</h2>
  
  <p>Solution according to the Method proposed by User Vorren:</p>
  
  <p>I opened up the registry editor, and navigated to the following Key:</p>
  
  <pre><code>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
  </code></pre>
  
  <p>, here i created a new key with the name of my Applikation:</p>
  
  <p>in this case : TestProjectExecutable.exe</p>
  
  <p>after that, the (default) value was set to  the full path of TestProjectExecutable.exe including the filename and extension. Then i created another String Value called "Path" and set the value to the folder where the dll was located:</p>
  
  <p><img src="https://i.stack.imgur.com/jYs75.png" alt="enter image description here"></p>