MATLAB engdemo.c VS Prof - Windows error compiling
조회 수: 3 (최근 30일)
이전 댓글 표시
Hallo Everyone,
I'm new with mex environment and right now i do multiple exercises from MATLAB External Application Handouts, such as the "engdemo.c". But the problem i get stuck since its compile always shows error.
>> mex engdemo.c
Building with 'Microsoft Visual C++ 2013 Professional (C)'.
Error using mex
LINK: error LNK2001: Unresolved external symbol "MexFunction".
Engdemo.lib: fatal error LNK1120: 1 non-resolved external
and then, i change the main() function with void mexFunction(), then come this error,
Error using mex
Library "engdemo.lib" and object "engdemo.exp"
created.
Engdemo.obj: error LNK2019: Reference to non-resolved external Symbol "engEvalString" in function "mexFunction".
Engdemo.obj: error LNK2019: Reference to non-resolved external
Symbol "engOpen" in function "mexFunction".
Engdemo.obj: error LNK2019: Reference to non-resolved external
Symbol "engClose" in function "mexFunction".
Engdemo.obj: error LNK2019: Reference to non-resolved external
Symbol "engGetVariable" in function "mexFunction".
Engdemo.obj: error LNK2019: Reference to non-resolved external
Symbol "engPutVariable" in function "mexFunction".
Engdemo.obj: error LNK2019: Reference to non-resolved external
Symbol "engOutputBuffer" in function "mexFunction".
Engdemo.mexw64: fatal error LNK1120: 6 non-resolved external
I've searched about this topic, and found several pages,such as i have to put the engmatopts.bat , since i use Windows. But i can't find this files.
http://148.204.81.206/matlab/matlab_external/compiling-engine-applications-with-the-mex-command.html#bsq78t5-1
Did anyone ever have the same problem and has the solution?
댓글 수: 0
답변 (1개)
Nagarjuna Manchineni
2017년 5월 15일
The MATLAB C/C++ engine library contain routines that allow you to call MATLAB from your own programs, using MATLAB as a computation engine.
The first error received is a linker error which indicates that the C/C++ source file that is being MEXed does not contain the MEX gateway function "mexFunction". That is the reason why you are able to proceed once you change the function signature of 'main()' to the following signature:
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
However, you can build the executables using mex command by specifying the flag '-client engine'. For example, the following command will create an executable (using main() method in engdemo.c not the mexFunction)
>> mex engdemo.c -client engine
If you want to create a 'mex' file for the same example, then change the function signature to 'mexFunction'. The linker errors that you are encountering now is due to the functions used in 'engdemo.c'. The functions 'engOpen', 'engClose', .., 'engOutputBuffer' are appearing in the 'engdemo.c' but the compiler/linker is not able to recognize them. So, you have to specify the proper headers and libraries while building with mex (C:\Program Files\MATLAB\R2016b is my 'matlabroot').
mex '-IC:\Program Files\MATLAB\R2016b\extern\include' '-LC:\Program Files\MATLAB\R2016b\extern\lib\win64\microsoft' -llibeng.lib -llibmx.lib engdemo.c
참고 항목
카테고리
Help Center 및 File Exchange에서 Call MATLAB from C에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!