"Generate Code Only" throws error for MATLAB block in Simulink
5 views (last 30 days)
Show older comments
Soham Sinha on 25 Aug 2021
Answered: Mark McBroom on 8 Sep 2021
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.
Mark McBroom on 8 Sep 2021
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.
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!