MATLAB Answers

0

Invalid MEX-file - Gateway function is missing.

Asked by Steve Hayward on 6 Aug 2019
Latest activity Commented on by Agapi Davradou on 11 Nov 2019 at 23:46
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.

Products


Release

R2018b

1 Answer

Answer by 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.

  2 Comments

Thanks. I will try that. But Microsoft Visual C++ 2017 family is on the list of supported compilers, so it ought to work.
Hello! Did you manage to solve the problem? I have the same error..
I am using Ubuntu 18.04 and Matlab R2019b.

Sign in to comment.