Undefined reference to mexPrintf for simple helloworld program
显示 更早的评论
I've been trying to get started using mex to compile c code for use in simulink s functions. The code below throws an undefined reference error upon compiling.
#include "mex.h"
#include <math.h>
#include <matrix.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mexPrintf("Hello World!\n");
}
undefined reference to `mexPrintf'
collect2.exe: error: ld returned 1 exit status
mex -setup displays
MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
Please let me know if you see the issue.
回答(1 个)
James Tursa
2018-9-4
编辑:James Tursa
2018-9-4
Your code is a standard mex routine that can be compiled and run at the MATLAB command line prompt as follows:
mex helloworld.c % or whatever the actual filename is
helloworld
s-function mex code has a different interface from what is in your code above that involves input & output ports etc. Maybe you could start with the s-function mex examples in the doc and then adapt it to what you need.
1 个评论
Mitchell Hoffmann
2018-9-4
编辑:Mitchell Hoffmann
2018-9-4
类别
在 帮助中心 和 File 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!