MATLAB Answers

Inserting C Code in Simulink block

24 views (last 30 days)
Hello;
I'm trying to learn how to insert C code in the user defined blocks of simulink, but I didn't have success.
I made this code in Code Composer Studio:
#include <stdio.h>
#include <math.h>
double y;
double u;
int main(void)
{
y=u*2;
return(y);
}
And I made this simple diagram
With this code in the matlab coder:
function y = callingmultiplicador(u)
%#codegen
y = 0.0;
y = coder.ceval('multiplicador',u);
But When i try to run, i obtain this error:
Warning c2_untitled.c: 180 missing prototype for multiplicador
Warning c2_untitled.c: 180 Missing prototype for 'multiplicador'
0 errors, 2 warnings
c2_untitled.obj .text: undefined reference to 'multiplicador'
"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\bin\lcc64.exe" -dll -noregistrylookup -c -Zp8 -DLCC_WIN64 -DMATLAB_MEX_FILE -DMX_COMPAT_32 -nodeclspec -I"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\include64" -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" -I"C:\Users\Alberto\Desktop" "untitled_sfun.c"
"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\bin\lcc64.exe" -dll -noregistrylookup -c -Zp8 -DLCC_WIN64 -DMATLAB_MEX_FILE -DMX_COMPAT_32 -nodeclspec -I"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\include64" -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" -I"C:\Users\Alberto\Desktop" "c2_untitled.c"
"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\bin\lcc64.exe" -dll -noregistrylookup -c -Zp8 -DLCC_WIN64 -DMATLAB_MEX_FILE -DMX_COMPAT_32 -nodeclspec -I"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\include64" -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" -I"C:\Users\Alberto\Desktop" "untitled_sfun_registry.c"
"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\bin\lcc64.exe" -dll -noregistrylookup -c -Zp8 -DLCC_WIN64 -DMATLAB_MEX_FILE -DMX_COMPAT_32 -nodeclspec -I"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\include64" -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" -I"C:\Users\Alberto\Desktop" "C:\Users\Alberto\Desktop\multiplicador.c"
"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\bin\lcc64.exe" -dll -noregistrylookup -c -Zp8 -DLCC_WIN64 -DMATLAB_MEX_FILE -DMX_COMPAT_32 -nodeclspec -I"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\include64" -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" -I"C:\Users\Alberto\Desktop" "C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\mex\lccstub.c"
"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\bin\lcclnk64.exe" -s -dll -L"C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\lib64" -entry LibMain -map sfun.map -o untitled_sfun.mexw64 @untitled_sfun.lmko
C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\bin\lccmake.exe: Error code 1
C:\Program Files\MATLAB\R2016a\sys\lcc64\lcc64\bin\lccmake.exe: 'untitled_sfun.mexw64' removed.
Component: Make | Category: Make error
Unable to create mex function 'untitled_sfun.mexw64' required for simulation.
Can you help to understand the problem???
Thanks
Regards

  0 Comments

Sign in to comment.

Accepted Answer

Rick Rosson
Rick Rosson on 15 Apr 2016
double multiplicador(double u) {
return 2.0*u;
}

  1 Comment

Alberto Prudhomme
Alberto Prudhomme on 16 Apr 2016
Thanks that works, but now I try another test but I have a rare error, but I will open another question for it. Thanks again.

Sign in to comment.

More Answers (0)

Sign in to answer this question.