title: How to manage libraries when building projects?
body: <p>I have a project <code>XXX</code> that depends on another framework <code>YYY</code>. The framework provides a <code>YYYConfig.cmake</code>. When I configure my project with <code>cmake-gui</code> I add the framework over the <code>YYY_DIR</code> variable. I generate and build the solution. Now when I run <code>XXX.exe</code> I get an error that a <code>.dll</code> from <code>YYY</code> couldn't be loaded. The <code>.lib</code> libraries and header files are found if I'm right.</p>
  
  <p>Online I've seen that <code>.dll</code> have to be put in the same folder where the <code>.exe</code> is located in. But why can't I just use the <code>.dll</code> that are already present in the installation folder of <code>YYY</code>? And is there a way to automatically put all <code>.dll</code> that my project needs into the right folder?</p>
  
  <p>I have the feeling that I'm lacking a bit of fundamental knowledge about deployment, so I'd highly appreciate any helpful reference or link about that. Thanks.</p>
  
  <hr>
  
  <p><em>Additional information</em></p>
  
  <p>I've built a framework, i.e. <a href="https://github.com/alicevision/AliceVision" rel="nofollow noreferrer"><em>AliceVision</em></a> using <code>vcpkg</code>, <code>cmake-gui</code> and Visual Studio 2019. The folder of the installed framework contains the following folders:</p>
  
  <ul>
  <li><code>bin</code> with many <code>.exe</code> and <code>.dll</code></li>
  <li><code>share</code> where <code>AliceVisionConfig.cmake</code> is located in</li>
  <li><code>include</code> with many <code>.hpp</code> of the framework and other dependencies</li>
  <li><code>lib</code> with many <code>.lib</code></li>
  </ul>
  
  <p>Now I try to create a simple test project with a <code>main.cpp</code></p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;aliceVision/system/cpu.hpp&gt;
  
  int main()
  {
      std::cout &lt;&lt; "Total cpus " &lt;&lt; aliceVision::system::get_total_cpus() &lt;&lt; std::endl;
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>and a <code>CMakeLists.txt</code></p>
  
  <pre><code>cmake_minimum_required(VERSION 3.3)
  
  project(AliceVisionAs3rdParty)
  
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
  
  find_package(AliceVision CONFIG REQUIRED)
  message(STATUS "Found AliceVision : ${AliceVision_FOUND}")
  message(STATUS "Found AliceVision version: ${AliceVision_VERSION}")
  
  add_executable(testAV3rd main.cpp)
  target_link_libraries(testAV3rd PUBLIC aliceVision_system)
  </code></pre>
  
  <p>When configuring with <code>cmake-gui</code> in the folder of my test project I'm just using a variable <code>AliceVision_DIR</code> to point at the folder <code>AliceVisionConfig.cmake</code> is located in. I'm using <code>vcpkg</code> for the toolchain, which is needed by the framework for some dependencies. Then I'm generating and building the solution. Here is the point where I'm starting the <code>.exe</code> and getting the message that a <code>aliceVision_system.dll</code> couldn't be found. It is present in the <code>bin</code> folder of the framework and as <code>aliceVision_system.lib</code> in the <code>lib</code> folder. I've checked the <code>.exe</code> with <a href="https://github.com/lucasg/Dependencies" rel="nofollow noreferrer"><em>Dependencies</em></a> and yes, it's this <code>.dll</code> that is not found. All the Windows <code>.dll</code> stuff is found ...</p>