title: Which dlls to include with my compiled executable - Distinguish between system and other dlls
body: <p>I have a c++ project that uses CMake to generate the build files. This project depends on external libraries for which I downloaded the necessary files from the internet (header, .lib and .dll). My project can compile and if the DLLs of the libraries are included in the <code>PATH</code>, or the DLLs are copied to the same place as the .exe of my project, it runs without a problem. Now I want to be able to run this program on another computer. For that, I need to know which DLLs I have to include alongside my .exe file.</p>
  <p>I have seen that the DLLs dependencies of any given dll or exe can be found using MVSC <a href="https://docs.microsoft.com/en-us/cpp/build/reference/dumpbin-reference?view=msvc-160" rel="nofollow noreferrer">dumpbin</a>. For example for this main:</p>
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QStyleFactory&gt;
  #include &lt;QFileDialog&gt;
  #include &lt;QStandardPaths&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  
  int main(int argc, char** argv)
  {
    // Create application
    QApplication app(argc, argv);
    app.setStyle(QStyleFactory::create(QStringLiteral(&quot;Fusion&quot;)));
  
    // Get file name
    QString file_name = QFileDialog::getOpenFileName(nullptr, QObject::tr(&quot;Open File&quot;),
                                                  QStandardPaths::displayName(QStandardPaths::HomeLocation),
                                                  QObject::tr(&quot;Images (*.png *.xpm *.jpg)&quot;));
  
    // Read image
    cv::Mat mat = cv::imread(file_name.toStdString());
  
    // Show image in opencv
    cv::namedWindow(&quot;display&quot;,cv::WINDOW_KEEPRATIO |cv::WINDOW_GUI_NORMAL );
    cv::imshow(&quot;display&quot;,mat);
    cv::waitKey(0);
  
    // Run application
    return app.exec();
  }
  </code></pre>
  <p>The output of the command <code>dumpbin /dependents main.exe</code> is:</p>
  <pre><code>Microsoft (R) COFF/PE Dumper Version 14.28.29912.0
  Copyright (C) Microsoft Corporation.  All rights reserved.
  
  
  Dump of file .\src\RelWithDebInfo\main.exe
  
  File Type: EXECUTABLE IMAGE
  
    Image has the following dependencies:
  
      Qt5Widgets.dll
      opencv_world347.dll
      Qt5Core.dll
      VCRUNTIME140.dll
      VCRUNTIME140_1.dll
      api-ms-win-crt-runtime-l1-1-0.dll
      api-ms-win-crt-math-l1-1-0.dll
      api-ms-win-crt-stdio-l1-1-0.dll
      api-ms-win-crt-locale-l1-1-0.dll
      api-ms-win-crt-heap-l1-1-0.dll
      KERNEL32.dll
      SHELL32.dll
  
    Summary
  
          1000 .00cfg
          1000 .data
          2000 .idata
          1000 .pdata
          3000 .rdata
          1000 .reloc
          1000 .rsrc
          6000 .text
  </code></pre>
  <p>In this case, I need this list of DLLsfor my program to run. However, some are system DLLs (KERNEL32.dll, SHELL32.dll...) and some are libraries that are not system DLLs (Qt5Widgets.dll, opencv_world347.dll...).</p>
  <p>Where should I decide to stop copying DLLsto ship my program? Should I ship it with <code>KERNEL32.dll </code>and <code>SHELL32.dll</code>, should I include <code>api-ms-win*.dll</code> or should I only include <code>Qt5Widgets.dll</code>, <code>Qt5Core.dll</code>, and <code>opencv_world347.dll</code>? <strong>How can I know from the list which are system DLLs and which are not?</strong></p>
  <p><strong>PS2</strong>: I know that specifically for Qt there is <a href="https://doc.qt.io/qt-5/windows-deployment.html" rel="nofollow noreferrer">windeployqt</a> that will automatically handle the Qt DLLs part and that the <code>VCRUNTIME140*.dll</code> part is also handled by installing <a href="https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0" rel="nofollow noreferrer">vc_redist</a></p>
  <p><strong>Note</strong>: The scope of this question is just to know where to stop. I am not interested in how to build an installer or how to automate that copy of the files or where to look for the dependent DLLs.</p>
  <p><strong>Note2</strong>: Questions <a href="https://stackoverflow.com/q/9410170/4179302">Find dependent modules of dll</a> and <a href="https://stackoverflow.com/q/24810738/4179302">how do I include dll's such as kernel32.dll which my unmanaged dll needs</a> did not provide an answer to my question.</p>