SegFault in OpenCV 2.4.2 and MinGW on WinXP
I am working on a WinXP machine. I downloaded and installed the prebuilt binaries OpenCV-2.4.2.exe
.
I am trying to build a very simple program using MinGW:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
Mat im = imread("lena.png");
if (im.empty()) {
return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}
This is how I am compiling:
g++ loadimg.cpp -I"${OPENCV_DIR}/include" -L"${OPENCV_DIR}/x86/mingw/lib" -lopencv_core242 -lopencv_highgui242 -lopencv_imgproc242 -o loadimg
where OPENCV_DIR
is an environment variable that points to OpenCV location:
$ echo $OPENCV_DIR
C:\Program Files\OpenCV\2.4.2\build
It compiles just fine, but I get a segfault when I try to run it:
I am using the the most recent MinGW (mingw-get update && mingw-get upgrade
):
$ g++ --version
g++.exe (GCC) 4.7.0
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For what it's worth, I can compile and run the above just fine in Visual Studio 10. My problem is using MinGW....
Any help is appreciated
Here is the output from GDB:
$ gdb ./loadimg.exe
GNU gdb (GDB) 7.4
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from c:\loadimg.exe...(no debugging symbols found)...done.
(gdb) r
Starting program: c:\loadimg.exe
[New Thread 2404.0xb9c]
Program received signal SIGSEGV, Segmentation fault.
0x6fc65dd8 in libstdc++-6!_ZNKSs7_M_dataEv () from C:\MinGW\bin\libstdc++-6.dll
(gdb) bt
#0 0x6fc65dd8 in libstdc++-6!_ZNKSs7_M_dataEv () from C:\MinGW\bin\libstdc++-6.dll
#1 0x6fc65d0b in libstdc++-6!_ZNKSs6_M_repEv () from C:\MinGW\bin\libstdc++-6.dll
#2 0x6fc65abb in libstdc++-6!_ZNKSs4sizeEv () from C:\MinGW\bin\libstdc++-6.dll
#3 0x6fc8ab0c in libstdc++-6!_ZNSs6assignEPKcj () from C:\MinGW\bin\libstdc++-6.dll
#4 0x63bb972a in cv::BmpDecoder::BmpDecoder() () from c:\Program Files\OpenCV\2.4.2\build\x86\mingw\bin\libopencv_highgui242.dll
#5 0x63bc470d in cv::ImageCodecInitializer::ImageCodecInitializer() () from c:\Program Files\OpenCV\2.4.2\build\x86\mingw\bin\libopencv_highgui242.dll
#6 0x63c3d9d3 in _GLOBAL__sub_I__ZN2cv6imreadERKSsi () from c:\Program Files\OpenCV\2.4.2\build\x86\mingw\bin\libopencv_highgui242.dll
#7 0x63b81d07 in __do_global_ctors () at ../mingw/gccmain.c:59
#8 0x63b810f3 in DllMainCRTStartup@12 (hDll=0x63b80000, dwReason=1, lpReserved=0x23fd30) at ../mingw/dllcrt1.c:83
#9 0x7c90118a in ntdll!LdrSetAppCompatDllRedirectionCallback () from C:\WINDOWS\system32\ntdll.dll
#10 0x63b80000 in ?? ()
#11 0x7c91d98a in ntdll!LdrHotPatchRoutine () from C:\WINDOWS\system32\ntdll.dll
#12 0x7c921d8c in ntdll!RtlMapGenericMask () from C:\WINDOWS\system32\ntdll.dll
#13 0x7c921c87 in ntdll!RtlMapGenericMask () from ...
@DaniilOsokin: thanks but using
namedWindow
didn't change anything. I'm still getting a segfault..@cuda.geek: thank you for the fix. I will have to wait for the next release to test it out, unless you know of a way to get the new version of the binaries affected, without building all of OpenCV myself :)
I tried gcc-4.6.2 and gcc-4.7.2 gcc-4.6.2 works fine but gcc-4.7.2 crash
how did u fix this problem . please help
@arpit88: the ideal solution is to build OpenCV from sources using your own version of MinGW (I had to do it for v2.4.3 to work with gcc-4.7.2)