Why I receive this error with the insertion of C code in Function Block in Simulink?????

24 views (last 30 days)
Hello,
I'm trying to continue learning how to insert C code in the function block of simulink, but I receive an error. These are the codes:
_ Main C:_
#include <stdio.h>
#include "dobloh.h"
double u;
double main(void) {
return 0;
}
double doble(double u){
double car;
car=2*u;
return car;
}
H header:
#ifndef DOBLADOR_C_
#define DOBLADOR_C_
double doble(double u);
#endif /* DOBLADOR_C_ */
CCS structure:
Matlab code inside the function block:
function y = callingdoble(u)
%#codegen
y=0.0;
y = coder.ceval('doble',u);
Simulink diagram:
Error message:
Warning while parsing custom code:
In line 1 of the custom code,
this declaration has no storage class or type specifier:
| dobloh.h
| ^ [2 similar]
Component: Stateflow | Category: General warningOpen
Failed to parse custom code specified in model configuration parameters dialog: Simulation Target -> Custom Code. Unresolved symbols are not reported.
Component: Stateflow | Category: General warning
Making simulation target "untitled_sfun", ...
"C:\Program Files\MATLAB\R2016a\bin\win64\mex.exe" -c -DMATLAB_MEX_FILE -I"C:\Users\Alberto\Desktop" -I"C:\Program Files\MATLAB\R2016a\extern\include" -I"C:\Program Files\MATLAB\R2016a\simulink\include" -I"C:\Program Files\MATLAB\R2016a\simulink\include\sf_runtime" -I"C:\Program Files\MATLAB\R2016a\stateflow\c\mex\include" -I"C:\Program Files\MATLAB\R2016a\rtw\c\src" -I"C:\Users\Alberto\Desktop\slprj\_sfprj\untitled\_self\sfun\src" untitled_sfun.c
Building with 'MinGW64 Compiler (C)'.
In file included from C:\Users\Alberto\Desktop\slprj\_sfprj\untitled\_self\sfun\src\untitled_sfun.c:4:0:
C:\Users\Alberto\Desktop\slprj\_sfprj\untitled\_self\sfun\src\untitled_sfun.h:26:7: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
dobloh.h
^
gmake: *** [untitled_sfun.obj] Error -1
Component: Make | Category: Make error
Unable to create mex function 'untitled_sfun.mexw64' required for simulation.
Component: Simulink | Category: Model error
Code of the file \untitled_sfun.h
#ifndef __untitled_sfun_h__
#define __untitled_sfun_h__
/* Include files */
#define S_FUNCTION_NAME sf_sfun
#include "sf_runtime/sfc_sf.h"
#include "sf_runtime/sfc_mex.h"
#include "sf_runtime/sf_runtime_errors.h"
#include "rtwtypes.h"
#include "simtarget/slClientServerAPIBridge.h"
#include "sf_runtime/sfc_sdi.h"
#include "sf_runtime/sf_test_language.h"
#include "multiword_types.h"
#include "sf_runtime/sfc_messages.h"
#include "sf_runtime/sfcdebug.h"
#define rtInf (mxGetInf())
#define rtMinusInf (-(mxGetInf()))
#define rtNaN (mxGetNaN())
#define rtIsNaN(X) ((int)mxIsNaN(X))
#define rtIsInf(X) ((int)mxIsInf(X))
struct SfDebugInstanceStruct;
extern struct SfDebugInstanceStruct* sfGlobalDebugInstanceStruct;
/* Custom Code from Simulation Target dialog*/
dobloh.h
/* Type Definitions */
/* Named Constants */
/* Variable Declarations */
extern uint32_T _untitledMachineNumber_;
/* Variable Definitions */
/* Function Declarations */
extern void untitled_initializer(void);
extern void untitled_terminator(void);
/* Function Definitions */
/* We load infoStruct for rtw_optimation_info on demand in mdlSetWorkWidths and
free it immediately in mdlStart. Given that this is machine-wide as
opposed to chart specific, we use NULL check to make sure it gets loaded
and unloaded once per machine even though the methods mdlSetWorkWidths/mdlStart
are chart/instance specific. The following methods abstract this out. */
extern mxArray* load_untitled_optimization_info(boolean_T isRtwGen, boolean_T
isModelRef, boolean_T isExternal);
extern void unload_untitled_optimization_info(void);
#endif
I hope you can help me to solve this.
Thanks a lot
Regards
Alberto

Accepted Answer

Alberto Prudhomme
Alberto Prudhomme on 16 Apr 2016
Solved!!,
I forget to declare the header in the configuration....

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!