"Generate Code Only" throws error for MATLAB block in Simulink

3 次查看(过去 30 天)
I want to generate C code from a Simulink model. My Simulink model has a MATLAB block. In the MATLAB block, I have called external c code with coder.ceval. However, the MATLAB block does not have an equivalent simulation target. I do not want to address any Simulation target but just want to generate equivalent C code from the Simulink block. In the Code Generation settings, I have selected, "Generate Code Only" in Build Process pane. However, I still get the following error when I click "Generate Code" in Embedded/Simulink Coder:
/home/soham/disk1/matlab/bin/mex -R2018a -silent LDFLAGS="\$LDFLAGS " -output samplemodel_sfun.mexa64 @samplemodel_sfun.mol c2_samplemodel.o: In function `sf_opaque_gateway_c2_samplemodel': c2_samplemodel.c:(.text+0x7af): undefined reference to `all_channels'
The `all_channels' is a variable defined in one of the header files, which I do include in MATLAB block with coder.cinclude. Could anyone explain why Embedded Coder calls mex even when I am only generating code and not any executable. How do we skip the Simulation target and only generate C code for target hardware. I want to build the C code with external build environment for the target hardware.

回答(1 个)

Mark McBroom
Mark McBroom 2021-9-8
Code is always generated from MATLAB Function blocks and compiled into a mex function, even if you select the "Generate code only" option. The same is true for Stateflow charts. One possible cause for the error is that the compiler can't find the header file. You could try adding the following statement to your matlab code to specify the directory that your header file is located in.
coder.updateBuildInfo('addIncludePaths', customDir)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by