code generation errors, mex compile works fine

I have written a s-function and then a tlc-file for code generation with embedded coder.
My s-function builds perfectly and also works fine within the simulink simulation.
However, when i build the model to generate code with embedded coder, I get the following error.
c:\program files\matlab\r2017a\extern\include\matrix.h(91): error C2061: syntax error: identifier 'mxLogical'
c:\program files\matlab\r2017a\extern\include\matrix.h(91): error C2059: syntax error: ';'
c:\program files\matlab\r2017a\extern\include\matrix.h(96): error C2061: syntax error: identifier 'mxChar'
.
.
.
Find attached file for complete log of the errors.
It looks like, code generation was successful but it could not build.
There are a lot of threads with similar problems but none have a clear answer to why this happens.
I have tried all the answers in the other threads, but I still have the same problem.
Can someone please explain what is happening and how can this be solved.

댓글 수: 6

Are you including matrix.h for the embedded code generation? If yes, perhaps you also need to include mex.h?
I had no need to use matrix.h for the s-function I created, and mex file was build successfully.
When I got the above-mentioned error during code-generation, I have included both
#include <<matrix.h>>
#include <<mex.h>>
in the s-function, there is no change in the errors that I get.
If you have a TLC, the S-function .c will not be used for code-generation, which is probably why you didn't see any change. The error is very strange. It almost seems like a compiler issue, but I can't be sure. Do your TLC modify the model header section, or do you include any custom headers using rtwmakecfg.m?
Hi Kastubha,
Past couple days I have tried to read through the documentation of TLC to see if I have made any errors in the TLC. The TLC file is as it should be and I can also see my generated code and it looks good.
Regarding your question about header sections, I have added following lines in tlc :
%assign MATLAB_ROOT = FEVAL("matlabroot")
%assign PATH_SEP = FEVAL("filesep")
%addincludepath "%<MATLAB_ROOT>%<PATH_SEP>toolbox%<PATH_SEP>rtw%<PATH_SEP>targets%<PATH_SEP>common%<PATH_SEP>can%<PATH_SEP>datatypes"
%addincludepath "%<MATLAB_ROOT>%<PATH_SEP>toolbox%<PATH_SEP>shared%<PATH_SEP>can%<PATH_SEP>canmex%<PATH_SEP>tlc_c"
%implements "sfunction_myfunction" "C"
%include "can_message.tlc"
%include "can_helpers.tlc"
%include "can_comm_setup.tlc"
%%Function: BlockTypeSetup ===============================================
%function BlockTypeSetup(block, system) void
%<RegisterCANDataType(block)>
%<SetupCanDataTypes(block)>
%assign canHdrFile = "Can_msg.h"
%assign canMsgHdrFile = "can_message.h"
%assign canDataTypeHdrFile = "can_datatype.h"
%assign canSfunUtilHdrFile = "sfun_can_util.h"
%<LibAddToCommonIncludes(canHdrFile)>
%<LibAddToCommonIncludes(canMsgHdrFile)>
%<LibAddToCommonIncludes(canDataTypeHdrFile)>
%<LibAddToCommonIncludes(canSfunUtilHdrFile)>
.
.
.
I still get the same error as in the attached log when I generate code using ert.tlc in code generation > System target file.
I also tried to generated code using grt.tlc, I get a preprocessor error : C:\PROGRA~1\MATLAB\R2017a\simulink\include\simstruc.h(364): fatal error C1189: #error: Must define one of RT, NRT, MATLAB_MEX_FILE, SL_INTERNAL, or FIPXT_SHARED_MODULE
If I add #define RT in my code, I get an additional error saying redefinition of RT.
Both the above errors I have faced are found in other threads in MATLAB community, but with no clear solution.
Your expertise is needed to understand these errors and solve it. Please provide us with your inputs and feedback.
Any idea how simstruc.h is getting included? Is the S-function .c file getting included in the generated code for the model? This shouldn't happen when you have a TLC, so it makes me wonder if your TLC isn't getting recognized for some reason.
Thanks for the reply.
The changes I make in the TLC file can be seen in the generated code, with that I have confirmed that tlc file is used for code generation. I have been successful in generating the code and also bulding it, I get the .exe as output only when I use grt.tlc. I have verified my simulation results with the exe results.
But I still cannot understand how to solve the error that I have attached in my question, which I get when I use ert.tlc as system target file for code generation. The generation is fine, the errors are during the build process.
I am stuck in this for days looking for a solution. Any help to move forward will be great.

댓글을 달려면 로그인하십시오.

답변 (1개)

Mark McBroom
Mark McBroom 2018년 2월 25일

0 개 추천

Sounds like your TLC file isn't being located. Make sure TLC file is in same directory as .mexw64 file for your s-function. You could also purposely introduce a syntax error into your TLC code or set a breakpoint (%breakpoint) in your TLC code to verify that it is being located and executed.

카테고리

도움말 센터File Exchange에서 Simulink Coder에 대해 자세히 알아보기

질문:

2018년 1월 3일

답변:

2018년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by