How do I include multiple C library headers with the same include guards in Simulink?

2 ビュー (過去 30 日間)

I have C code that describes the functionality of two systems. The codebase contains files with identical names but different content, and they also share the same header include guards. I would like to use these two systems in the same Simulink model. For example:

When I try to separate the files using Simulink Libraries, I get syntax errors while building the model.

Error(s) encountered while building simulation target MEX-file for model 'two_blocks'.
Caused by:

Microsoft (R) Program Maintenance Utility Version 14.37.32825.0
Copyright (C) Microsoft Corporation. All rights reserved.

### Compiling two_blocks_cgxe.c
cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "E:\ML_MATLAB64\R2023b\extern\include" /I "E:\ML_MATLAB64\R2023b\simulink\include" /I "E:\ML_MATLAB64\R2023b\rtw\c\src" /I "E:\ml_workspace\c_function_article\slprj\_cgxe\two_blocks\src" /I "E:\ml_workspace\c_function_article" /I "E:\ML_WORKSPACE\c_function_article\slprj\_cprj" /I "E:\ML_WORKSPACE\c_function_article\slprj\_cgxe\two_blocks\src" /I "E:\ML_WORKSPACE\c_function_article" /I "E:\ML_WORKSPACE\c_function_article\slprj\_slcc\OHf1uuaSWAsj9L9zbRSKeC" /I "E:\ML_WORKSPACE\c_function_article\slprj\_slcc\rzKA0zoVhTuLQia7fzdvOF" /I "E:\ml_workspace\c_function_article\block_1" /I "E:\ml_workspace\c_function_article\block_2" "two_blocks_cgxe.c"
two_blocks_cgxe.c
E:\ML_WORKSPACE\c_function_article\slprj\_slcc\OHf1uuaSWAsj9L9zbRSKeC\slcc_interface_OHf1uuaSWAsj9L9zbRSKeC.h(17): error C2146: syntax error: missing ')' before identifier 'inp'
E:\ML_WORKSPACE\c_function_article\slprj\_slcc\OHf1uuaSWAsj9L9zbRSKeC\slcc_interface_OHf1uuaSWAsj9L9zbRSKeC.h(17): error C2061: syntax error: identifier 'inp'
E:\ML_WORKSPACE\c_function_article\slprj\_slcc\OHf1uuaSWAsj9L9zbRSKeC\slcc_interface_OHf1uuaSWAsj9L9zbRSKeC.h(17): error C2059: syntax error: ';'
E:\ML_WORKSPACE\c_function_article\slprj\_slcc\OHf1uuaSWAsj9L9zbRSKeC\slcc_interface_OHf1uuaSWAsj9L9zbRSKeC.h(17): error C2059: syntax error: ')'
NMAKE : fatal error U1077: 'cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "E:\ML_MATLAB64\R2023b\extern\include" /I "E:\ML_MATLAB64\R2023b\simulink\include" /I "E:\ML_MATLAB64\R2023b\rtw\c\src" /I "E:\ml_workspace\c_function_article\slprj\_cgxe\two_blocks\src" /I "E:\ml_workspace\c_function_article" /I "E:\ML_WORKSPACE\c_function_article\slprj\_cprj" /I "E:\ML_WORKSPACE\c_function_article\slprj\_cgxe\two_blocks\src" /I "E:\ML_WORKSPACE\c_function_article" /I "E:\ML_WORKSPACE\c_function_article\slprj\_slcc\OHf1uuaSWAsj9L9zbRSKeC" /I "E:\ML_WORKSPACE\c_function_article\slprj\_slcc\rzKA0zoVhTuLQia7fzdvOF" /I "E:\ml_workspace\c_function_article\block_1" /I "E:\ml_workspace\c_function_article\block_2" "two_blocks_cgxe.c"' : return code '0x2'
Stop.

Is there a way to include both headers in the source code for the same model?

採用された回答

MathWorks Support Team
MathWorks Support Team 2024 年 10 月 7 日
There are two ways to do this:
1) Encapsulate the C Function block in a model reference (see the screenshot below). This way one wrapper C file per model is created.
2) Modify the include guard names to ensure that each header file has a distinct include guard.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Environment Customization についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by