Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Troubleshooting (Windows)

Amro edited this page Nov 18, 2017 · 4 revisions

Troubleshooting (Windows)

Invalid MEX-file or Segmentation fault

Some references from MATLAB documentation:

Check the following common issues first:

  • Make sure the system PATH is set up correctly. This is different from addpath() in MATLAB. You must have the correct DLL files visible in the system path, depending on the MATLAB architecture and the compiler.

  • A supported MEX compiler is setup correctly. In Windows 64-bit environment, Windows SDK compiler is needed for Visual C++ Express editions. Note that if you change the compiler configuration, you should clean any previously compiled MEX-files mexopencv.make('clean',true) and build again from scratch.

If you still see the "Invalid MEX-file" error messages, and you are using OpenCV DLL's manually built from sources, check that a consistent value of _SECURE_SCL flag was used during compilation. The current version of mexopencv.make script explicitly adds _SECURE_SCL=1 flag in the build command for Visual Studio compilers older than 2010, so that the built MEX-files are compatible with the OpenCV binary distribution. If you manually built OpenCV with different _SECURE_SCL flag, edit mexopencv.make file and change the flag to use a consistent value.

When unspecified, the default value of the _SECURE_SCL flag depend on the version of the Visual Studio compiler, and whether building is in "Debug" or "Release" mode:

  • VS2010 and newer: In debug mode, the default value for _SECURE_SCL is 1. In release mode, the default value for _SECURE_SCL is 0.
  • VS2008 and older: The default value for _SECURE_SCL is 1.

Alternatively, you can change the default value for the _SECURE_SCL flag in mex command. To change the default configuration, which is created with the mex -setup command in MATLAB, is located in the following path in recent versions of Windows.

%AppData%\MathWorks\MATLAB\(version)\mexopts.bat

Open this file and edit /D_SECURE_SCL option. Note that this is usually only necessary for VS2008 and older.

If you see "Invalid MEX-file" error even when having matched the _SECURE_SCL flag, it probably indicates some other compatibility issues. Please file a bug report at https://github.com/kyamagu/mexopencv/issues . Specify your OS and compiler, MATLAB and OpenCV versions, along with any error messages and/or crash reports.

Visual Studio 2008 compatibility issue

Some users reported incompatibility with Visual Studio 2008. The current minimum recommended version to build mexopencv is VS2010. For this reason, mexopencv on Windows platform does not work with MATLAB R2009b or earlier.

Nevertheless, if you want to try using Visual Studio 2008, obtain stdint.h and use mexopencv.make to compile the package. Visual Studio 2008 or earlier does not comply with C99 standard and lacks stdint.h header file. Luckily, the header file is available on the Web. For example, here.

Place this file under include directory in the mexopencv package.