AST --> CGScope Error When Using Custom Code

5 views (last 30 days)
Haowen
Haowen on 23 Dec 2024
Answered: David Balbuena on 2 Jan 2025
I'm trying to integrate the Pinocchio with Simulink for some robot development work.
I created a .cpp file and compiles with g++ in terminal and the executable runs fine.
However, when I add the .cpp file and its dependencies (compiler, include, header, library files) in the Simulink custom code configuration, it returns:
Failed to convert AST --> CGScope
There is no other information available in the diagnostic viewer.
  1 Comment
Haowen
Haowen on 26 Dec 2024
FYI: I can compile using mex on my source .cpp file and run the generated mexa64 files in the MATLAB command window. When I setup the c caller or c function block in Simulink, it alwasy returns Failed to convert AST --> CGScope.
Can Mathworks staff give more insight on this error message? There is no other error shown in the diagonostic viewer.

Sign in to comment.

Answers (1)

David Balbuena
David Balbuena on 2 Jan 2025
You're hitting a bug with the parser that Simulink uses to parse through all symbols in your header file. If you are able to share your code, you can contact MathWorks Technical Support to report the bug: Contact Support - MATLAB & Simulink
You can workaround it by writing a wrapper .cpp/.h file and providing the wrapper to Simulink. You can see an example of that here: Call C++ Class Methods Using C-Style Wrapper Function from C Function Block
The example uses C Function block, but you can apply this style to C Caller block as well.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!