MATLAB Answers

Invalid MEX-file - Gateway function is missing.

80 views (last 30 days)
Steve Hayward
Steve Hayward on 6 Aug 2019
Answered: Victor Eijkhout on 18 Mar 2020
I recently installed MATLAB 2018b under Windows10. When I compile the mex function example yprime.c using the Microsoft Visual C++ 2017 compiler I get the following error at run-time
Invalid MEX-file 'C:\work\yprime.mexw64': Gateway function is missing.
The output from MEX in verbose mode is appended below.
>> mex -v yprime.c
Verbose mode is on.
... Looking for compiler 'Microsoft Visual C++ 2017 (C)' ...
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\').
... Executing command 'set "vcroot=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional"&for /f "delims= " %a in ('type "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"') do @if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe" call echo %vcroot%' ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...Yes ('C:\Program Files (x86)\Windows Kits\10\').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\').
... Executing command 'set "vcroot=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional"&for /f "delims= " %a in ('type "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"') do @if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe" call echo %vcroot%\VC\Tools\MSVC\%a' ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat' ...Yes.
... Looking for folder 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots' KitsRoot10 ...Yes ('C:\Program Files (x86)\Windows Kits\10\').
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots' KitsRoot10 ...Yes ('C:\Program Files (x86)\Windows Kits\10\').
... Executing command 'echo off&set "sdkversion="&(for /f %a IN ('dir "C:\Program Files (x86)\Windows Kits\10\include\" /b /ad-h /on') do ( @if exist "C:\Program Files (x86)\Windows Kits\10\include\%a\ucrt\" set "sdkversion=%a" ))&call echo %sdkversion%' ...Yes ('10.0.17134.0').
Found installed compiler 'Microsoft Visual C++ 2017 (C)'.
Set PATH = C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\vcpackages;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools;C:\Program Files (x86)\Windows Kits\10\\Bin\10.0.17134.0\x64;C:\Program Files (x86)\Windows Kits\10\\Bin\10.0.17134.0\x86;C:\Program Files (x86)\Windows Kits\10\\Bin\x64;C:\Program Files (x86)\Windows Kits\10\\Bin\x86;;C:\Program Files\Microsoft MPI\Bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\MATLAB\2018b\runtime\win64;C:\Program Files\MATLAB\2018b\bin;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Users\sdhayward\AppData\Local\Microsoft\WindowsApps;
Set INCLUDE = C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\atlmfc\include;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\winrt;C:\Program Files\Matlab\2018b\extern\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\atlmfc\include;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\winrt;C:\Program Files\Matlab\2018b\extern\include;
Set LIB = C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\atlmfc\lib\x64;C:\Program Files (x86)\Windows Kits\10\\Lib\10.0.17134.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\\lib\10.0.17134.0\um\x64;C:\Program Files\Matlab\2018b\lib\win64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\atlmfc\lib\x64;C:\Program Files (x86)\Windows Kits\10\\Lib\10.0.17134.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\\lib\10.0.17134.0\um\x64;C:\Program Files\Matlab\2018b\lib\win64;
Set LIBPATH = C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\atlmfc\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\atlmfc\lib\x64;
Options file details
-------------------------------------------------------------------
Compiler location: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\
Options file: C:\Users\sdhayward\AppData\Roaming\MathWorks\MATLAB\R2018b\mex_C_win64.xml
CMDLINE200 : link /nologo /manifest /DLL /EXPORT:mexFunction /EXPORT:mexfilerequiredapiversion C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\yprime.obj C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\c_mexapi_version.obj /LIBPATH:"C:\Program Files\Matlab\2018b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /out:yprime.mexw64
CMDLINE250 : mt -outputresource:yprime.mexw64;2 -manifest "yprime.mexw64.manifest"
CMDLINE300 : del "yprime.exp" "yprime.lib" "yprime.mexw64.manifest" "yprime.ilk"
COMPILER : cl
COMPFLAGS : /Zp8 /GR /W3 /EHs /nologo /MD
COMPDEFINES : /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE
MATLABMEX : /DMATLAB_MEX_FILE
OPTIMFLAGS : /O2 /Oy- /DNDEBUG
INCLUDE : -I"C:\Program Files\Matlab\2018b\extern\include" -I"C:\Program Files\Matlab\2018b\simulink\include"
DEBUGFLAGS : /Z7
LINKER : link
LINKFLAGS : /nologo /manifest
LINKTYPE : /DLL
LINKEXPORT : /EXPORT:mexFunction
LINKEXPORTVER : /EXPORT:mexFunction /EXPORT:mexfilerequiredapiversion
LINKLIBS : /LIBPATH:"C:\Program Files\Matlab\2018b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
LINKDEBUGFLAGS : /debug /PDB:"yprime.mexw64.pdb"
LINKOPTIMFLAGS :
OBJEXT : .obj
LDEXT : .mexw64
SETENV : set COMPILER=cl
set COMPFLAGS=/c /Zp8 /GR /W3 /EHs /nologo /MD /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /DMATLAB_MEX_FILE
set OPTIMFLAGS=/O2 /Oy- /DNDEBUG
set DEBUGFLAGS=/Z7
set LINKER=link
set LINKFLAGS=/nologo /manifest /export:%ENTRYPOINT% /DLL /LIBPATH:"C:\Program Files\Matlab\2018b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /EXPORT:mexFunction
set LINKDEBUGFLAGS=/debug /PDB:"%OUTDIR%%MEX_NAME%.mexw64.pdb"
set NAME_OUTPUT=/out:"%OUTDIR%%MEX_NAME%%MEX_EXT%"
VCROOT : C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional
SDKROOT : C:\Program Files (x86)\Windows Kits\10\
VSINSTALLDIR : C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\
VCINSTALLDIR : C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726
VCVARSALLDIR : C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build
KITSROOT : C:\Program Files (x86)\Windows Kits\10\
SDKVERSION : 10.0.17134.0
MATLABROOT : C:\Program Files\Matlab\2018b
ARCH : win64
SRC : "C:\work\yprime.c";"C:\Program Files\Matlab\2018b\extern\version\c_mexapi_version.c"
OBJ : C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\yprime.obj;C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\c_mexapi_version.obj
OBJS : C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\yprime.obj C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\c_mexapi_version.obj
SRCROOT : C:\work\yprime
DEF : C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\yprime.def
EXP : "yprime.exp"
LIB : "yprime.lib"
EXE : yprime.mexw64
ILK : "yprime.ilk"
MANIFEST : "yprime.mexw64.manifest"
TEMPNAME : yprime
EXEDIR :
EXENAME : yprime
OPTIM : /O2 /Oy- /DNDEBUG
LINKOPTIM :
CMDLINE100_0 : cl /c /Zp8 /GR /W3 /EHs /nologo /MD /O2 /Oy- /DNDEBUG /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE -I"C:\Program Files\Matlab\2018b\extern\include" -I"C:\Program Files\Matlab\2018b\simulink\include" "C:\work\yprime.c" /FoC:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\yprime.obj
CMDLINE100_1 : cl /c /Zp8 /GR /W3 /EHs /nologo /MD /O2 /Oy- /DNDEBUG /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE -I"C:\Program Files\Matlab\2018b\extern\include" -I"C:\Program Files\Matlab\2018b\simulink\include" "C:\Program Files\Matlab\2018b\extern\version\c_mexapi_version.c" /FoC:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\c_mexapi_version.obj
-------------------------------------------------------------------
Building with 'Microsoft Visual C++ 2017 (C)'.
cl /c /Zp8 /GR /W3 /EHs /nologo /MD /O2 /Oy- /DNDEBUG /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE -I"C:\Program Files\Matlab\2018b\extern\include" -I"C:\Program Files\Matlab\2018b\simulink\include" "C:\work\yprime.c" /FoC:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\yprime.obj
yprime.c
cl /c /Zp8 /GR /W3 /EHs /nologo /MD /O2 /Oy- /DNDEBUG /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE -I"C:\Program Files\Matlab\2018b\extern\include" -I"C:\Program Files\Matlab\2018b\simulink\include" "C:\Program Files\Matlab\2018b\extern\version\c_mexapi_version.c" /FoC:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\c_mexapi_version.obj
c_mexapi_version.c
link /nologo /manifest /DLL /EXPORT:mexFunction /EXPORT:mexfilerequiredapiversion C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\yprime.obj C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\c_mexapi_version.obj /LIBPATH:"C:\Program Files\Matlab\2018b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /out:yprime.mexw64
Creating library yprime.lib and object yprime.exp
Recompile embedded version with '/DMATLAB_MEXCMD_RELEASE=R2017b'
cl /c /Zp8 /GR /W3 /EHs /nologo /MD /O2 /Oy- /DNDEBUG /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE -I"C:\Program Files\Matlab\2018b\extern\include" -I"C:\Program Files\Matlab\2018b\simulink\include" "C:\Program Files\Matlab\2018b\extern\version\c_mexapi_version.c" /FoC:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\c_mexapi_version.obj /DMATLAB_MEXCMD_RELEASE=R2017b
c_mexapi_version.c
link /nologo /manifest /DLL /EXPORT:mexFunction /EXPORT:mexfilerequiredapiversion C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\yprime.obj C:\Users\SDHAYW~1\AppData\Local\Temp\mex_61341289482682_12072\c_mexapi_version.obj /LIBPATH:"C:\Program Files\Matlab\2018b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /out:yprime.mexw64
Creating library yprime.lib and object yprime.exp
mt -outputresource:yprime.mexw64;2 -manifest "yprime.mexw64.manifest"
Microsoft (R) Manifest Tool
Copyright (c) Microsoft Corporation.
All rights reserved.
del "yprime.exp" "yprime.lib" "yprime.mexw64.manifest" "yprime.ilk"
MEX completed successfully.

  0 Comments

Sign in to comment.

Answers (2)

Victor Eijkhout
Victor Eijkhout on 18 Mar 2020
No thanks to the staff person: the answer was in stackoverflow: you need to make sure your function is literally:
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )

  0 Comments

Sign in to comment.


Subhadeep Koley
Subhadeep Koley on 9 Aug 2019
MinGW is one of the supported compiler in MATLAB R2018ba for MEX file compilation according to the documentation. Therefore, try compiling your MEX file with MinGW
Download MinGW free of charge from here.

  5 Comments

Show 2 older comments
Rishi Malhan
Rishi Malhan on 1 Dec 2019
I have a similar problem when using ubuntu 16. Was anyone able to figure out a solution to this problem?
Jiajia
Jiajia on 14 Feb 2020
I have a similar problem when using ubuntu 18 and Matllab R2018a. Was anyone able to figure out a solution to this problem?
Victor Eijkhout
Victor Eijkhout on 18 Mar 2020
Suggesting a different compiler is a cop-out. I'm using g++ which is supported too. This should just be a matter of a syntax error.

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by