Inserting C Code in Simulink block

3 次查看(过去 30 天)
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

采纳的回答

Rick Rosson
Rick Rosson 2016-4-15
double multiplicador(double u) {
return 2.0*u;
}
  1 个评论
Alberto Prudhomme
Alberto Prudhomme 2016-4-16
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by