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

조회 수: 6 (최근 30일)
Soham Sinha
Soham Sinha 2021년 8월 25일
답변: Mark McBroom 2021년 9월 8일
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에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by