How do I make an executable that I can run on another computer (Windows)

Basically I have a program that uses OpenCV and would like run it on other computers without having to install OpenCV. I want to make the installation as simple as possible.

Tried running an exe file on another computer, but it said the following:
“The code execution cannot proceed because opencv_world420d.dll was not found. Reinstalling the program may fix this problem.”

How am I able to make it work?

You have to copy the needed OpenCV DLL files(and maybe other DLLs which come with the compiler) along with the executable (in the same folder - or the system folder).

The easiest way is to copy opencv_world420.dll (try to link to the release version of the library, which doesn’t end with “d”). If you want to reduce the file size, rebuild OpenCV without opencv_world and copy only the needed DLL files (opencv_core420.dll, opencv_imgproc420.dll etc.)

I have done that to some success. If the computer has Visual C++, it would run perfectly. However, when a machine does not have Visual C++ (in particular, one machine I tested on said "The code execution cannot proceed because CONCRT140D.dll was not found), it did not run. How do I fix this?

Thanks!

As I said, you also need other DLL files. CONCRT140D.dll makes part of the Visual C++ compiler dependencies. You either copy these files too, or give the Visual C++ redistributable installer.

You can try the dependency walker to get the list of all the needed DLLs.

Anyway, the DLL hell is a real PITA for Windows.

Inside the Visual Studio installation directory are executables for installing the exact version of the redistributable you require, e.g. VS 2022

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\v143

alternatively you can download the latest version of the redistributable from the microsoft website

You can use static linking, see c++ - Can I fully statically link a MFC application? - Stack Overflow

You might need to recompile opencv with the right runtime “version”, because if you mix code/binaries that were compiled with dynamic and static microsoft runtime (and other variants like single/multi-threaded and debug/release) you will corrupt your heap.

Fir static linking you probably want the /MT flag