Error using mex G:\Matlab_WS\code_test\Assignment1\Add_Two.c:3:1: warning: return type defaults to 'int' [-Wimplicit-int] Add_Two(U16 a, U16 b)
Afficher commentaires plus anciens
Trying to understand mex compilation with an example, but getting compilation error. Below are the commands that I used to compile. Mex file is generated but its compilation failed.
def = legacy_code('initialize');
def.SourceFiles = {'Add_Two.c'};
def.HeaderFiles = {'Add_Two.h'};
def.SFunctionName = 'Add_Two_SFun';
def.OutputFcnSpec = 'uint32 y1 = Add_Two(uint16 u1, uint16 u2)';
legacy_code('sfcn_cmex_generate', def);
>> legacy_code('compile', def)
### Start Compiling Add_Two_SFun
mex('-IG:\Matlab_WS\code_test\Assignment1', '-c', '-outdir', 'C:\Users\Shafi\AppData\Local\Temp\tp548d5365_ef4a_45c6_9aec_e200ba5a55ff', 'G:\Matlab_WS\code_test\Assignment1\Add_Two.c')
Building with 'MinGW64 Compiler (C)'.
Error using mex
G:\Matlab_WS\code_test\Assignment1\Add_Two.c:3:1: warning: return type defaults to 'int'
[-Wimplicit-int]
Add_Two(U16 a, U16 b)
^
G:\Matlab_WS\code_test\Assignment1\Add_Two.c:3:1: error: conflicting types for 'Add_Two'
In file included from G:\Matlab_WS\code_test\Assignment1\Add_Two.c:1:0:
G:\Matlab_WS\code_test\Assignment1/Add_Two.h:11:5: note: previous declaration of 'Add_Two' was here
U32 Add_Two(U16 a, U16 b);
^
Error in legacycode.LCT/compile
Error in legacycode.LCT.legacyCodeImpl
Error in legacy_code (line 101)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
***************************************************
Input files:
Add_Two.c:
#include <Add_Two.h>
Add_Two(U16 a, U16 b)
{
U32 add_result;
U32 output;
add_result = (U32)a + (U32)b;
if(THOUSAND > add_result)
{
output = add_result;
}
else
{
output = SUM_DEFAULT;
}
return output;
}
Add_Two.h:
#ifndef ADD_TWO_H_
#define ADD_TWO_H_
typedef unsigned int U16;
typedef unsigned long int U32;
#define THOUSAND (U32)1000
#define SUM_DEFAULT (U32)25
U32 Add_Two(U16 a, U16 b);
#endif
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!