How can I implement coder.ceval in Simulink?
古いコメントを表示
I have written a function using the editor:
function y = barry_fcn(u) %#codegen
(assert(isa(u,'single')))
if isempty(coder.target)
y = cos(u)
else
y = single(0)
y = coder.ceval('math_cosf',u)
end
end
I can successfully build code using this command:
codegen -config:lib barry_fcn math.c hilton_math.h
However, I wish to be able to generate this code from a simulink model using a MATLAB function block inside this model with the same code, if I try this I end up with the following error:
"c2_eval_cos_code.c(199) : warning C4013: 'math_cosf' undefined; assuming extern returning int
c2_eval_cos_code.c(199) : warning C4244: '=' : conversion from 'int' to 'real32_T', possible loss of data
### Linking ...
link.exe /nologo /dll /OPT:NOREF /export:mexFunction /OUT:eval_cos_code_sfun.mexw64 /map:"eval_cos_code_sfun.map" "C:\Program Files\MATLAB\R2012b\stateflow\c\mex\lib\win64\sfc_mex.lib" "C:\Program Files\MATLAB\R2012b\stateflow\c\debugger\lib\win64\sfc_debug.lib" "C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmx.lib" "C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmex.lib" "C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmat.lib" "C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libfixedpoint.lib" "C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libut.lib" "C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmwmathutil.lib" "C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libemlrt.lib" "C:\Program Files\MATLAB\R2012b\lib\win64\libippmwipt.lib" "C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmwblascompat32.lib" @eval_cos_code_sfun.mol
Creating library eval_cos_code_sfun.lib and object eval_cos_code_sfun.exp
c2_eval_cos_code.obj : error LNK2019: unresolved external symbol math_cosf referenced in function sf_c2_eval_cos_code
eval_cos_code_sfun.mexw64 : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\link.exe"' : return code '0x460'
Stop. "
採用された回答
その他の回答 (1 件)
Ryan G
2012 年 10 月 26 日
0 投票
From the error and based on the line you use to generate the code, it looks like it can't find the libraries you utilized, math.c and hilton_math.h. Hence, it does not know where this function belongs.
I would have to look a little deeper to find out how to include the h-files, but don't have the time right this moment, I will edit this answer if I figure it out.
カテゴリ
ヘルプ センター および File Exchange で Event Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!