Reading constants and variables from external header files in Matlab Coder

8 次查看(过去 30 天)
If I have the C header file external_vars.h containing:
const int ext_var = 5;
How do I use it in a Matlab Coder generated C function? The following code doesn't work, as ext_var is not defined in the Matlab code.
function external_test() %#codegen
coder.cinclude('external_vars.h')
a = ext_var;
end

采纳的回答

Denis Gurchenkov
Denis Gurchenkov 2019-5-2
If you have an Embedded Coder license, you can use coder.storageclass to bind an extern C variable to a variable in MATLAB function: https://www.mathworks.com/help/ecoder/ref/coder.storageclass.html?s_tid=doc_ta
Without Embedded Coder, one possible workaround is to have a C function that reads/writes to this variable, and call that C function using coder.ceval.
  1 个评论
Philip Bergander
Philip Bergander 2019-5-2
Thanks for the response! I considered the workaround earlier too, and it might be enough for my use. I'll realise if the use of ecoder is necessary, in that case my employer will have to get a license.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by