Program only executes if I run it in Visual Studio - c++

I have been trying to find a solution for this problem but I haven't been able to see/find any answer that correctly solves it.
I coded a program (Qt + OpenCV) that works fine when I run it with Visual Studio, but trying to run the executable it simply does not execute anything. The program doesn't give any error: it just never starts.
I am not sure where to start checking what is happening and why it is not even starting (I could understand lack of libraries, some other error..).
I am basically interested on what are the best way of checking why a program runs when executed from the IDE and not from the executable created. As I said, I was expecting an error message if something was wrong. Any ideas? Any good programming advice regarding how to avoid this problem in the future?
Edit: I forgot to mention that I am coding with a Windows XP machine. It doesn't work in this machine when I try to execute the file. It executes normally on a W7 machine but not in other W7 machine.

The executable will need the QT libraries on the computer that you are running it on. On linux there is command (I think ldd) that will show you what libraries your executable needs. I am not sure about Windows but there should be something similar. At least on a linux computer it will not necessarily give you an error if the QT libraries are missing. The executable just seems to do nothing.

Try copying the executable into the same directory as the .dll files in the Qt 'bin' directory.
If that works then you just need to put the Qt bin directory into your path, or copy the dlls into the windows\system directory

You need not only the correct dlls in your path (best in the application directory), but also the plugins in the correct location. See my answer to the question: Qt dll deployment on windows.

Related

When I execute an .exe (compiled on my machine) on another computer it give me this error

It's my first time using Visual Studio 2017. I built a simple program in C++ on my PC. I was curious to see if my program works on another PC. I tried to execute the .exe on the other computer and it gave me this kind of error:
vs(some letters and numbers).dll is missing.
I assume that the .dll in question is part of Visual Studio.
I tried on a third PC, and this time the cmd stops working and becomes unresponsive after I execute my .exe.
I also have this problem when I compile with MinGW using the g++ compile feature in the cmd. When I execute the program compiled with MinGW on another PC, it gives me the same error, but this time it says something like
gw...dll is missing
Is there a way to avoid this error without installing the Visual Studio (or MinGW at this point) on any other PC I want my program to run on?
If you're interested in the code, I can put it here, but I don't think it's the problem here because I have the same issue for every other .exe compiled on my PC.
Here's a picture of the error:
In case of Visual Studio, you need to install Visual C++ Redistributable libraries or provide the libraries that are required by your application with .exe file (I am not sure if it violates license or not though).
In case of MinGW, you need to provide required DLL as well. I guess that you need libgcc_s_dw2-1.dll and libstdc++-6.dll, but you would better check it yourself. And remember about the license.
You may use Dependency Walker to analyse dependencies of your application.
UPDATE (2017-12-12):
I've missed the time you posted the screenshot. As far as I see from it the problem is that you are trying to run debug version of your executable: ucrtbased.dll is the debug version of the ucrtbase library and is only available (from what I know) from Visual Studio distribution. If you want to run your application on the computers that do not have installed Visual Studio, then you should use the Release version of your application.
In order to understand your problem you need to understand the concept of DLL.
Dynamic-link library(DLL) - As described by Microsoft:
A DLL is a library that contains code and data that can be used by
more than one program at the same time. For example, in Windows
operating systems, the Comdlg32 DLL performs common dialog box related
functions. Therefore, each program can use the functionality that is
contained in this DLL to implement an Open dialog box. This helps
promote code reuse and efficient memory usage.
So to put it simply, DLL is basically a bunch of compiled code, which is being linked to your code at load (or even run-time). Now, of course if your system is missing the DLL, your progrem will fail to work. To make things even worse, DLL are sensitive to the compiler that was used. So each DLL might have multiple version, so you will need to right DLL.
Now to the problem itself, the error message are the best way to start. They guide you what DLL are missing, and what is their name. For instance in your case "vs*.dll" is most likely related to Visual C++ runtime redistributable.
Finally, please note you have another consideration to make in addition to make your own system work: Every one that will use your code might face the exact same problem. So if you actually intend to share your .EXE with other people, you will need to understand how to guide them, or even automate their installation process.

Stand-alone app with wxWidgets

I've got a problem with my app, when it comes to executing it in compiled .exe form. I am new in this and I don't know where the problem is. I already tried to search this problem on Google & this site but nothing what I found helped me.
I am using Code::Blocks IDE with MinGW and wxWidgets 2.8.X installed.
Everything works fine inside IDE, but when I try to run it as exe - already compiled - I get an error like this:
The program can not start because the computer is missing wxmsw28u_gcc_custom.dll.
Try to solve this problem by reinstalling the program.
When I copy this .dll file right next to my .exe then it will execute without any errors.
Any clues how to fix it ? I guess it's easy to fix but I really don't know how ...
It needs the DLL file to execute. You can either ship that with your app, or compile wxWidgets as a static library, so that it will be shipped in your .exe file (thus making it bigger).

Qt5Cored.dll missing when trying to run application

I'm using Visual Studio 2013 Ultimate.
My Qt version is 5.2.1
Am using a specific build for VS2013 which I obtained from here.
Now, what I did:
Created a new Qt Application from Visual Studio.
Typed in my logic and the code.
Built it successfully in x64 Debug mode.
Ran the application successfully.
Everything good so far.
Now the problem:
I restart my Visual Studio and load the project.
It is built successfully (in x64 Debug).
Now, am unable to run it. I get the error:
The program can't start because Qt5Cored.dll is missing from your computer.
Try reinstalling the program to fix this problem.
It ran the first time when I created the application. Now it won't run.
I tried simulating the problem, and this happens everytime. Runs the first time, and doesn't run after Visual Studio restart.
Please help me resolve this issue.
Thanks in advance.
From project properties you have to go to debugging -> Environment -> and write PATH=qt5 dll paths Or you have to put the dlls next to the exe.
The first time you in debug mode. Probably in that case Qt5Cored.dll (with a d in the name) was used. Maybe in the second build, you build in release mode, and for some reason Qt5Core.dll is not found in the PATH.
here is what i did and it worked :D
first : make sure you are building a release version not a debug version
second : it asked for the qt5core.dll when you copy it to the same path of your program it may ask for other *.dll files so i put the program in the folder containing all the dlls :D
which is
C:\Qt\Qt5.7.0\5.7\mingw53_32\bin
or according to your installation ..it worked well
any way this folder (as i think) contains all DLL libraries you may need with your program
so to know what exactly you need from it try to start your program many times in another location and in every time you will know another dll needed according to your programming ..
that method worked but i think there may be a more cleaver solutions we have to dig for :)

c++ program failed to run on another pc with libgcc error

I wrote some simple code in C++, and I built it and ran it on my laptop, and everything as working. When I tried to run the .exe file on my brother's laptop, it gave me this error The program can't start because libgcc_s_sjlj-1.dll is missing from your computer. Try reinstalling the program to fix this problem. Am I missing something that I should have added or something?
Note: I don't know if it matters or not, but I'm using Code::Blocks.
Thanks
It matters because you used Code::Blocks. If you don't know about it, you most probably used Code::Blocks with MinGW. Install it on that machine followed by a reboot may fix it.
C++ programs need to have a runtime library -- you can think of it as needing .NET Framework to run C# or JRE to run Java programs. Visual C++ uses msvcrt (known as Visual C++ Runtime). Many installations of Windows seem to come with msvcrt by default which may explain why people using MSVC is less likely to run into issues like this.
If you statically link the CRT (C Run Time) you can lift the requirements of the clients having to have the DLL files installed, at the expense of having a larger .exe file.
A relevant SO answer: The program can't start because libgcc_s_dw2-1.dll is missing
You can place that DLL in the same folder as the .exe on your release and it should work

Program can't start because *.dll is missing - MinGW, Eclipse, Windows 7

I am well aware of the fact that a multitude of similar problems already appeared on this board, however none of the solutions helped me.
I am trying to get Eclipse CDT running with MinGW toolchain on Windows 7 Service Pack 1. I already did that on Windows XP and thought that the same procedure will make it run smoothly on Windows 7, but it seems I was mistaken ;)
After installing MinGW from the automatic installer (just in case I installed a few things more than what I needed) and adding the C:/MinGW/bin to my PATH environment variable, I tried to compile a simple Hello, World! program. Eclipse did not give me any errors, but it didn't want to give any output in the Console window. Alarmed, I tried to run the executable file outside of Eclipse and got the error that
"Program can't start because libstdc++-6.dll is missing".
Strangely enough, this dll is in the C:/minGW/bin directory, so the PATH variable should 'find' it - but it does not. Copying the dll to the directory with the executable file helped, but it is obviously a short-term solution and I would prefer to have a more "normal" one.
The thing that makes my problem different, I think, from the others I've noticed on this board is the fact that, for one, Eclipse does not find any errors with my PATH variable (which it usually does, if the MinGW was not included in the Path variable or something), and besides the required dlls are where they should be, but it seems my Windows can't find them.
The "real" solution is indeed to copy the DLL locally. You have to ship that dll when shipping your EXE.