[Create mexfunction from C code] warning: implicit declaration of function
Afficher commentaires plus anciens
why I got this warning message "warning: implicit declaration of function 'myfunction' " when I build the mex function?
#include <mex.h>
#include <matrix.h>
#include<stdio.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int argc = 0;
char **argv;
int i, result;
argc = nrhs;
argv = (char **) mxCalloc( argc, sizeof(char *) );
for (i = 0; i < nrhs; i++){
if( !mxIsChar( prhs[i] ) ){
mexErrMsgTxt("Input must be of type char.");
return;
}
argv[i] = mxArrayToString( prhs[i] );
}
result = myfunction( argc, argv );
for( i=argc-1; i<=0; i-- )
mxFree( argv[i] );
mxFree( argv );
if( result )
mexErrMsgTxt("main function causes an error");
}
float square ( float x )
{
float p ;
p = x * x ;
return ( p ) ;
}
int myfunction(int argc, char *argv[]){
float m, n ;
m=5;
n = square(m);
printf ( "\nSquare of the given number %f is %f",m,n );
}
>> mex myfunction.c
Building with 'MinGW64 Compiler (C)'.
D:\TestMexFunction\myfunction.c: In function 'mexFunction':
D:\TestMexFunction\myfunction.c:21:14: warning: implicit declaration of function 'myfunction' [-Wimplicit-function-declaration]
result = myfunction( argc, argv );
^~~~~~~~~~
I am using Matlab 64bit and the code works if I remove the square() function
Réponse acceptée
Plus de réponses (0)
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!