필터 지우기
필터 지우기

Trying to get matlab mex file to work

조회 수: 11 (최근 30일)
Stagleton
Stagleton 2011년 11월 15일
답변: CHUANQIANG ZHANG 2019년 5월 12일
I've been trying to run a c file in matlab with mex function. I have been getting this same error that's below. I cannot edit the names of the directory files because I do not have admin access. Everything was created automatically. I downloaded VS2010e as the compiler.
>> mex -v -g mexcallmatlab.c
-> Default options filename found in C:\Users\gsea\AppData\Roaming\MathWorks\MATLAB\R2010b
----------------------------------------------------------------
-> Options file = C:\Users\gsea\AppData\Roaming\MathWorks\MATLAB\R2010b\mexopts.bat
MATLAB = C:\Program Files (x86)\MATLAB\R2010b
-> COMPILER = cl
-> Compiler flags:
COMPFLAGS = /c /Zp8 /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD
OPTIMFLAGS = /O2 /Oy- /DNDEBUG
DEBUGFLAGS = /Z7
arguments =
Name switch = /Fo
-> Pre-linking commands =
-> LINKER = link
-> Link directives:
LINKFLAGS = /dll /export:mexFunction /LIBPATH:"C:\Program Files (x86)\MATLAB\R2010b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 -lkernel32 user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\gsea\AppData\Local\Temp\mex_Xt7aAg\templib.x" /MAP:"mexcallmatlab.mexw64.map"
LINKDEBUGFLAGS = /debug /PDB:"mexcallmatlab.mexw64.pdb"
LINKFLAGSPOST =
Name directive = /out:"mexcallmatlab.mexw64"
File link directive =
Lib. link directive =
Rsp file indicator = @
-> Resource Compiler = rc /fo "mexversion.res"
-> Resource Linker =
----------------------------------------------------------------
--> cl /c /Zp8 /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD /FoC:\Users\gsea\AppData\Local\Temp\mex_Xt7aAg\mexcallmatlab.obj -I"C:\Program Files (x86)\MATLAB\R2010b"\extern\include /Z7 -DMX_COMPAT_32 mexcallmatlab.c
mexcallmatlab.c
Contents of C:\Users\gsea\AppData\Local\Temp\mex_Xt7aAg\mex_tmp.rsp:
C:\Users\gsea\AppData\Local\Temp\mex_Xt7aAg\mexcallmatlab.obj
--> link /out:"mexcallmatlab.mexw64" /debug /PDB:"mexcallmatlab.mexw64.pdb" /dll /export:mexFunction /LIBPATH:"C:\Program Files (x86)\MATLAB\R2010b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 -lkernel32 user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\gsea\AppData\Local\Temp\mex_Xt7aAg\templib.x" /MAP:"mexcallmatlab.mexw64.map" @C:\Users\gsea\AppData\Local\Temp\mex_Xt7aAg\mex_tmp.rsp
LINK : warning LNK4044: unrecognized option '/lkernel32'; ignored
LINK : fatal error LNK1104: cannot open file 'mexcallmatlab.mexw64'
C:\PROGRA~2\MATLAB\R2010B\BIN\MEX.PL: Error: Link of 'mexcallmatlab.mexw64' failed.
??? Error using ==> mex at 208
Unable to complete successfully.
>>
  댓글 수: 4
Kaustubha Govind
Kaustubha Govind 2011년 11월 15일
Also, do you have write permissions to your directory? Try running the mex command after starting MATLAB "as administrator".
Stagleton
Stagleton 2011년 11월 15일
how do I run the mex command as administrator?

댓글을 달려면 로그인하십시오.

채택된 답변

Friedrich
Friedrich 2011년 11월 15일
Hi,
seems like you are trying to compile the example file in the directory where it comes with MATLAB. Under Windows 7 or Vista the UAC blocks write access to the C:\Program Files\... folders, which results in such an error. Try to copy that file to a folder where you have write access and compile it in there.
  댓글 수: 2
Kaustubha Govind
Kaustubha Govind 2011년 11월 15일
In addition, I am also uncomfortable with the use of the name "mexcallmatlab" - I would recommend using a different name because this clashes with the name of the MEX-API function mexCallMATLAB.
Stagleton
Stagleton 2011년 11월 15일
This sounds right, I don't have admin access on my work pc. I tried to copy the file to the desktop but still got the same error. In order to install the SDK and Microsoft Studio 2010 C++ I had to use "Windows 7 Elevated Installer".
I tried another file name 'array1.c' also. After running the command "mex array1.c", I get an output file 'array1.mexw64' but the same error as before. Is there a way around this?

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Stagleton
Stagleton 2011년 11월 15일
sorry for the dumb question. To create a mex function I was not making a proper gateway. My c files were not written correctly.

Eduardo
Eduardo 2013년 5월 31일
Hi, I am using Visual Studio with matlab and I get the same error as your when I try to compile something with the mex command:
Please how did you solve it??
LINK : fatal error LNK1181: cannot open input file 'kernel32.lib'
C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Link of 'field_extract.mexw64' failed.
??? Error using ==> mex at 208 Unable to complete successfully.
  댓글 수: 2
Friedrich
Friedrich 2013년 6월 3일
Most likely a bittedness missmatch. Make sure you configured the project to be a 64bit project. Otherwise the 32bit compiler tries to open the 64bit kernel32.lib which results in the error you get.
moataz hassan
moataz hassan 2013년 12월 4일
You need to run windows update VS10sp1-KB983509. the problem will be solve

댓글을 달려면 로그인하십시오.


CHUANQIANG ZHANG
CHUANQIANG ZHANG 2019년 5월 12일
I had similar problem. I was running MATLAB 2019a under windows 10.
To solve the problem, please try to run with Windows 7 compatible mode, and admin.
See attached picture. Good luck!
捕获.JPG

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by