필터 지우기
필터 지우기

LINK : error LNK2001: unresolved external symbol mexFunction

조회 수: 29 (최근 30일)
Amit Kalhapure
Amit Kalhapure 2012년 6월 9일
댓글: jacky chen 2013년 10월 20일
I am trying to run multiple .cpp source files in matlab2010a using following command
mex mesh.cpp blueacmodel.cpp redacmodel.cpp
It is showing error:
LINK : error LNK2001: unresolved external symbol mexFunction
C:\USERS\AMIT\APPDATA\LOCAL\TEMP\MEX_3K~1\templib.x : fatal error LNK1120: 1 unresolved externals
C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Link of 'mesh.mexw32' failed.
What to do?
mesh.cpp is the main code.
Thanks in advance.
  댓글 수: 1
jacky chen
jacky chen 2013년 10월 20일
I just have the same error, finally I got it ,which maybe can help u, I get a demo from someone, I find Mex some file can fix that error, because one document maybe use another . with a common rule , u should use #include "mex.h" and mexFunction

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

답변 (2개)

Jan
Jan 2012년 6월 9일
One of the C-source files needs to gateway function "mexFunction()". Does this function exist anywhere?
[EDITED, reply to comments]
When a compiled function is called from Matlab, the mexFunction is started. It receives the inputs in prhs and replies the outputs in plhs. The function main() is not used automatically. Perhaps you want:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
main();
return;
}
But more likely the program content should be moved inside the mexFunction. Matlab contains a bunch of examples in [matlabroot]/extern/examples/mex . It would be a good idea to study them and read the corresponding documentation, e.g. "doc mexFunction",
  댓글 수: 2
Amit Kalhapure
Amit Kalhapure 2012년 6월 10일
Thanks for your reply. How to use "mexFunction()"?
I tried doing this way :
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
return;
}
int main(void)
{
<program content>
}
Now the program gets executed, but I don't see anything as output. Whats's the reason? Am I defining the "mexFunction()" incorrectly?
Thanks again.
Jan
Jan 2012년 6월 10일
See [EDITED].

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


Pouye Sedighian
Pouye Sedighian 2012년 8월 1일
Hi, I had the same problem and I defined a mexFunction as has been mentioned above. I ran the program and I got the below error:
OpenCVTest2.cpp OpenCVTest2.cpp(8) : error C2061: syntax error : identifier 'mxArray'
C:\PROGRA~2\MATLAB\R2010A\BIN\MEX.PL: Error: Compile of 'OpenCVTest2.cpp' failed.
??? Error using ==> mex at 222 Unable to complete successfully.
I need to fix this as soon as possible. Would you please let me know what I need to do?
  댓글 수: 3
Pouye Sedighian
Pouye Sedighian 2012년 8월 1일
*: error C2061: syntax error : identifier 'mxArray' 1>Build log was saved at "file://c:\Users\Sahand\Documents\Visual Studio 2008\Projects\OpenCVTest2\OpenCVTest2\Debug\BuildLog.htm" 1>OpenCVTest2 - 1 error(s), 1 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Pouye Sedighian
Pouye Sedighian 2012년 8월 1일
#include "stdafx.h" #include cv.hpp #include cxcore.hpp #include highgui.h
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
cv::Mat img = cv::imread("C:\\1.jpg"); cv::imshow("OpenCV",img);
cv::waitKey();
return EXIT_SUCCESS;
} ******************* Thanks a lot, The above is the error I got. If I have the above code I got the error this function is returing a value, it should not! if I remove it and jut write "return;" I get the above error! What do I need to do?

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

카테고리

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