Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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);

    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

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 <>
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:
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 C:\WINDOWS\system32\ntdll.dll
#14 0x7c90e457 in ntdll!LdrCreateOutOfProcessImage () from C:\WINDOWS\system32\ntdll.dll