LINK : error LNK2001: unresolved external symbol mexFunction

27 次查看(过去 30 天)
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.

请先登录,再进行评论。


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