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!