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 PATH, 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.
I have seen that the DLLs dependencies of any given dll or exe can be found using MVSC dumpbin. For example for this main:
#include <QApplication>
#include <QStyleFactory>
#include <QFileDialog>
#include <QStandardPaths>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char** argv)
{
// Create application
QApplication app(argc, argv);
app.setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
// Get file name
QString file_name = QFileDialog::getOpenFileName(nullptr, QObject::tr("Open File"),
QStandardPaths::displayName(QStandardPaths::HomeLocation),
QObject::tr("Images (*.png *.xpm *.jpg)"));
// Read image
cv::Mat mat = cv::imread(file_name.toStdString());
// Show image in opencv
cv::namedWindow("display",cv::WINDOW_KEEPRATIO |cv::WINDOW_GUI_NORMAL );
cv::imshow("display",mat);
cv::waitKey(0);
// Run application
return app.exec();
}
The output of the command dumpbin /dependents main.exe is:
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
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...).
Where should I decide to stop copying DLLsto ship my program? Should I ship it with KERNEL32.dll and SHELL32.dll, should I include api-ms-win*.dll or should I only include Qt5Widgets.dll, Qt5Core.dll, and opencv_world347.dll? How can I know from the list which are system DLLs and which are not?
PS2: I know that specifically for Qt there is windeployqt that will automatically handle the Qt DLLs part and that the VCRUNTIME140*.dll part is also handled by installing vc_redist
Note: 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.
Note2: Questions Find dependent modules of dll and how do I include dll's such as kernel32.dll which my unmanaged dll needs did not provide an answer to my question.