title: Building opencv with mingw. Fails when I import cv2. DLL load failed. Looking for .dll, but I have .dll.a's
body: <p>I'm trying to build OpenCV with MSYS / MinGW so I can use the cv2 module in python. 
  I'm on Windows 7 64-bit and using 32 bit Python 2.7. Building OpenCV works, but I cannot seem to use it without getting an "ImportError: DLL load failed: The specified module could not be found." after importing cv2. I've been debugging it for awhile, and the common google solutions seem not to work. </p>
  
  <p>These are the steps I have taken: </p>
  
  <ul>
  <li>Removed all other instance of opencv from my computer (there were a few)</li>
  <li><p>Built opencv with CMake and I manually set these flags: </p>
  
  <pre><code>         'CMAKE_INSTALL_PREFIX'       : 'C:/Program Files (x86)/OpenCV'
           'CMAKE_BUILD_TYPE'           : 'Release',
           'CMAKE_C_FLAGS'              : '-m32',
           'CMAKE_CXX_FLAGS'            : '-m32',
           'BUILD_opencv_gpu'           : False,
           'BUILD_opencv_gpuarithm'     : False,
           'BUILD_opencv_gpubgsegm'     : False,
           'BUILD_opencv_gpucodec'      : False,
           'BUILD_opencv_gpufeatures2d' : False,
           'BUILD_opencv_gpufilters'    : False,
           'BUILD_opencv_gpuimgproc'    : False,
           'BUILD_opencv_gpuoptflow'    : False,
           'BUILD_opencv_gpustereo'     : False,
           'BUILD_opencv_gpuwarping'    : False
  </code></pre></li>
  <li><p>I do a cmake -G "MSYS Makefiles" ..., make -j9, and finally a make install. The printouts show that the libraries go where I expect them to. </p></li>
  <li><p>My PATH includes</p>
  
  <pre><code>         C:\MinGW\bin
           C:\MinGW\msys\1.0\bin
           C:\MinGW\libexec\gcc\mingw32\4.6.2
           C:\Python27\
           C:\Python27\Scripts
           C:\Program Files (x86)\OpenCV
           C:\Program Files (x86)\OpenCV\lib
  </code></pre></li>
  <li><p>My PYTHONPATH includes</p>
  
  <pre><code>         C:\Python27\Lib\site-packages
           C:\Python27
  </code></pre></li>
  <li><p>I then copy </p>
  
  <ul>
  <li><p>cv2.pyd and libcv2.dll.a from C:\Python\Lib\site-packages </p></li>
  <li><p>all libopencv_*249.dll.a from C:\Program Files (x86)\OpenCV\lib</p></li>
  <li><p>libgcc_s_dw2-1.dll libstdc++-6.dll from C:\MinGW\bin </p></li>
  <li><p>I MOVE ALL OF THESE into a directory I named cv2</p></li>
  </ul></li>
  <li><p>In the cv2 directory I made an __init__.py file containing the following code: </p>
  
  <pre><code>     import os, sys
       from os.path import realpath, dirname
       tpl_cv2 = realpath(dirname(__file__))
       print(tpl_cv2)
       sys.path.insert(0,tpl_cv2)
       os.environ['PATH'] = tpl_cv2 + os.pathsep + os.environ['PATH']
       try:
           from cv2 import *
       except Exception as ex:                       
           print(repr(ex))
           print(os.environ['PATH'])
           print(sys.path)
           raise
  </code></pre></li>
  <li><p>I then open a IPython terminal and enter the command "import cv2"</p></li>
  </ul>
  
  <p>And I get the error: ImportError('DLL load failed: The specified module could not be found.',)</p>
  
  <hr>
  
  <p>To debug this I've: </p>
  
  <ul>
  <li>I load up the cv2.pyd file in depends.exe It shows that </li>
  </ul>
  
  <p>LIBOPENCV_CALIB3D249.DLL and all the other opencv libs are not found. However, these are all in the same directory as cv2.pyd as well as in both the PATH and PYTHONPATH. </p>
  
  <p>But they are named .dll.a because I compiled with MSYS / MinGW. I don't understand why its looking for the .dll without the .a suffix. I think this probably has something to do with the error, but I don't know where to go from here. </p>
  
  <ul>
  <li><p>I've also built a small C++ application which reads and image using the OpenCV that I've built. It builds just fine, but I get the error: The program can't start because libopencv_core249.dll is missing from your computer. So, I'm more convinced this .dll.a thing is the issue.</p></li>
  <li><p>I've tried simply renaming the libs from .dll.a to .dll, but that didn't work. </p></li>
  </ul>
  
  <p>I'm hoping someone can shed light on this issue. </p>