OpenCV program compiles but doesn't run - c++

I am working on Windows 8 with OpenCV 2.4.13 and MinGW 4.9.
I wrote a simple and small opencv program to check if everything was installed properly. Following is the code:
#include <opencv2/highgui/highgui.hpp>
int main () {
printf("in main\n");
for (int i = 0; i<10; i++) {
printf("here\n");
IplImage * image = cvLoadImage("C:/{...}/test.jpg");
cvReleaseImage(&image);
}
return 0;
}
I compiled it with the following command at the command prompt:
g++ -o test test.cpp -LC:\{...}\opencv\build\x64\vc11\lib -lopencv_core2413 -lopencv_highgui2413 -IC:\{...}\opencv\build\include
{...} is the path to the specified folder/file.
This command runs properly and compilation is successful without any errors. However, when I run it with:
test
in main and one here gets printed after which I get the error message as 'test.exe has stopped working. Windows is looking for a solution.'
What all I have tried:
For installation of OpenCV, ran the downloaded opencv executable file (which extracts all files) and added the system variable OPENCV_DIR and edited the system PATH for location of DLLs (which reside in %OPENCV_DIR%\bin) as per:
http://docs.opencv.org/2.4/doc/tutorials/introduction/windows_install/windows_install.html#installation-by-using-the-pre-built-libraries
Tried adding the required DLLs in the same directory as the .exe.
Tried doing the whole thing from vc12 directory.
After the error message appears, it gives an option of debugging. On pressing that, the Just In Time Debugger opens up and says 'An unhandled win32 exception occurred in test.exe'. I googled this and tried inspecting the registry key as directed here
https://support.microsoft.com/en-us/kb/811191
but it was already properly set. So, there was nothing for me to change in that.
Nothing is working for me at all. Please let me know if any more information is required. I'm desperately looking for a solution to this.

For those who might be encountering the same problem, I compiled the program with OpenCV dynamic (.dll) libraries instead of the .lib files and it ran just fine at runtime for some reason.

Related

Failed to locate: "CL.exe". The system cannot find the file specified

I'm trying to get into SDL2 in C++ and I have followed all the steps in a variety of YouTube tutorials. I am using vs2019, and every time I try to run anything I get this error: Failed to locate: "CL.exe". The system cannot find the file specified.
For example, it happens when I try running this code:
#include "SDL.h"
#undef main
#include <iostream>
int main() {
int x = 1;
std::cout << "Hello World!\n";
std::cin.ignore();
return 0;
}
I have followed all of the steps, but nothing seems to work. Similar questions have been asked, but their solutions don't work for me. I'm just running it in the editor. Can anybody help me?
You need to run VCVARSALL.BAT for Visual studio 2019 in the console for making cl.exe available.
Alternatively you can run "Developer Command Prompt for VS 2019" from the Start menu and run cl.exe there (after changing the appropriate working directory to one containing your code).
I am going to post this as a potential answer, pending OP’s clarification to what he means by “running it in the editor”.
MSVS does not install with the C and C++ compiler and libraries unless you specifically ask for them. To install them you must re-run the installer. You will eventually get a screen with a lot of different options on it. It is a tabbed page with “Workloads”, “Individual Components”, and “Language Packs” at the top.
Find and make sure that you select both:
“Universal Windows Platform development”
“Desktop development with C++”
Continue as usual. The installer will update MSVS with the ability to compile C and C++ programs.
You can also read Microsoft’s instructions.

Error in opencv function in .exe file but not in debug nor release

One more time, I want to ask for your help after long and unfruitful researches.
I have developped an app using OpenCV which works very well is Visual Studio in debug and release mode.
I tried to deploy it, but i get a fatal error when I start the .exe. By using a log file and doing tests, I figured out the problem was in function cv::resize in the following code :
Mat logo = imread("lena.png");
cv::resize(logo, logo, Size(), 0.55, 0.55, INTER_CUBIC);
I found very weird that i can call cv::imread (and cv::Mat) without throwing exception but not resize.
If I try to run the .exe created by the compilation in release mode, i get the following errod code : 0xc000007b.
I read it could be a problem of compatibility between 32/64-bits dll, without being able to solve it. I try to build a 64-bits appplication. The path for opencv lib is define like this : C:\opencv\build\x64\vc14\lib
Thank you for your help,
Valentin B

qt compiles successfully but runs fail

I compiled bitoin-qt,PTS coin and other Altercoins successfully ,but thay all can't running.
I use MinGW4.4 ,QT 4.8.5 download from website and QT creator 2.8.1.
This is my .pro setting:
BOOST_LIB_SUFFIX=-mgw44-mt-s-1_53
BOOST_INCLUDE_PATH=D:/C/coin/namecoinq/libs/boost_1_53_0
BOOST_LIB_PATH=D:/C/coin/namecoinq/libs/boost_1_53_0/stage/lib
BDB_INCLUDE_PATH=D:/C/coin/namecoinq/libs/db-4.8.30.NC/build_unix
BDB_LIB_PATH=D:/C/coin/namecoinq/libs/db-4.8.30.NC/build_unix
OPENSSL_INCLUDE_PATH=D:/C/coin/namecoinq/libs/openssl-1.0.1e/include
OPENSSL_LIB_PATH=D:/C/coin/namecoinq/libs/openssl-1.0.1e
MINIUPNPC_INCLUDE_PATH=D:/C/coin/namecoinq/libs
MINIUPNPC_LIB_PATH=D:/C/coin/namecoinq/libs/miniupnpc-1.8
And I uncommented this code because MinGW4.4 doesn't suport it(I've used MinGW 4.6,4.7,4.8,but they all even compiled failed) :
#win32:QMAKE_LFLAGS *= -Wl,--dynamicbase -Wl,--nxcompat
These all compiled by MinGW4.4 succefully,but the debug and release exe compiled both can't run.I have coped the qt dlls to the exe direction.When I debugged it,it broke before entering the main source.
======================UPDATE edit==========================
I know it's because of leveldb,but I don't know what's wrong with my compiling leveldb:
TARGET_OS=NATIVE_WINDOWS mingw32-make libleveldb.a libmemenv.a
When I use another altercoin leveldb source code,the error solves.But I use back to the original leveldb source code,the program breaks again.
Still seems to me you are missing a .dll. Try using dependency walker and verify you are not missing any dependencies.

"windows cannot access the specified device....." error in c++

I am MFC guy working on visual studio 2010 create some executables using visual studio!! but on linux and mac my executables are not working as usual windows!!.
So i decided to use "MinGW" compiler to create executables.
Note:-Please give me one suggestion is that," is minGW is best compiler for cross plateform working ??or any thing else is there??"
I successfully install WinGW compiler on my C drive and start working with following program..
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello ";
return 0;
}
I compile it using following command,
g++ -static-libgcc -static-libstdc++ Main.cpp
I found one executable in same folder with name a.exe :).Working fine:)
But after some time i decide to modified same program in following manner like,
int main ()
{
return 0;
}
I compile it with same command but when i execute it using command line it show me error "Access is denied so i goto that folder and run same executable as "Run as Administrator" it show me one messagebox with the message windows cannot access the specified device path or file. you may not have appropriate permissions
---EDIT--
follwing code is NOT WORKING:-
int main ()
{
int k;
return 0;
}
but this program WORKING :-
int main()
{
int k;
k = 0;
return 0;
}
If you are getting this access denied error, then the most likely cause is that the executable file is open in another process, probably the linker or debugger. Try installing Process Explorer and hit Ctrl+F and type in the name of your .exe. This should show the processes that the .exe file open. Kill those processes (or if you are still debugging, then end debugging first). You then should be able to build again.
Note that this has nothing to do with Microsoft APIs, as in any case you're using gcc.
EDIT: If there are no processes holding the .exe then it may be that there is some other kind of permission problem. Does the .exe file exist? Can you delete the file and rebuild? Another thing to try is run Process Monitor and filter for the name of the .exe -- that may show a regular permission denied error, or perhaps another error such as a sharing conflict.
Note:-Please give me one suggestion is that," is minGW is best compiler for cross plateform working ??or any thing else is there??"
No. And there's nothing else out there.
Use whatever compiler is available on target platform, ensure your code compiles on all of them.
Avoid platform-specific and compiler-specific code at all costs (use cross-platform frameworks).
I successfully install WinGW
There are many different versions of mingw provided by different sites. If you install compiler from mingw.org using mingw-get, it'll probably work. If you install mingw from some other site, it may or may not work.
I compile it using following command,
Use a build systems. cmake, qmake or something similar.
it show me error "Access is denied
Launch process monitor and see after which system call it terminates. It is also possible that your antivirus software interferes with your program, or maybe there's some stray dll in your path or something like that.
Check the permissions for the entire folder in which the executable resides. Trying to 'Run as Administrator' doesn't have any effect if the folder doesn't allow the permissions.
It doesn't have anything to do with your code. This is an environmental problem, something is pretty messed up about the permissions your user account has for one or more of the directories on your hard disk. The generic diagnostic is that the default working directory for the program does not permit read or list access.
A possible starting point would be to use Explorer and right-click the directory where MinGW is installed. Use the Security tab and ensure that your user account has all permissions enabled. Further narrow it down to trying to run the program from the command prompt, using different directories as the default directory.

Simple program, no callstack, "inpossible" to find error

When I run on my working machine (win7 VS2010 ultimate sp1)
int main()
{
unsigned i = 5;
i %= 0;
return 0;
}
or
int main()
{
int * ip = 0;
*ip = 4;
return 0;
}
and I get Integer division by zero unhandled exception. When I hit break button, to see the problem, my Call stack contains only msvcrt100d and ntdll and Visual studio breaks me inside file mlock.c on the LeaveCriticalSection( _locktable[locknum].lock ); line.
When I run this code on another machine(win7 VS2010 proff sp1), VS breaks it exactly on the problematic line i %= 0; od *ip = 4.
This mistake was hidden somewhere within my project and I wasn't able to find it till I run it on another machine. How can I fix this behavior? I need to see it on my working machine.
I have a clean installation of Windows 7, clean installation Visual Studio 2010 and VS-SP1.
My project should not be ruined. I generate it using CMake and same project working fine on non-working machine.
Any advice would be greatly appreciated.
Ok, I have found a solution.
In VS go to exceptions settings (ctrl + alt + e) and check Thrown in required Win32 Exceptions.
More info can be found
here and here.
SO related question here.
When you compile a program with VS it creates the EXE file and a PDB file with all the relevant debugging information of the program. Also, the absolute path of the PDB if embedded into the EXE.
When the EXE crashes and you use VS to debug it, it tries to find the corresponding PDB, both in the same folder than the EXE and in the absolute path embedded in the file. If you want it to be able to debug the program, then you must copy the PDB along with the EXE. Note that these two files must come from exactly the same compilation, or else it will not work.
Then, the VS debugger will try to show you the sources of the program, again using the absolute path of the *.c or *.cpp files embedded in the PDB. Obviously, if you want it to stop in the relevant line, you need a copy of the sources! If you copy the sources to the very same path than in the original machine it should work without problems. If not, you have to open the Call stack window, double-click over the main function and it will ask you to browse for the actual sources.
Or maybe your setup is screwed...