Undefined reference to mexPrintf for simple helloworld program
Afficher commentaires plus anciens
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.
Réponses (1)
James Tursa
le 4 Sep 2018
Modifié(e) : James Tursa
le 4 Sep 2018
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 commentaire
Mitchell Hoffmann
le 4 Sep 2018
Modifié(e) : Mitchell Hoffmann
le 4 Sep 2018
Catégories
En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!