# Simulink Use C Function Block

Use when integrating legacy code, custom code, or C/C++ code into Simulink via C...

- Repository: https://github.com/matlab/simulink-agentic-toolkit (1305 stars)
- Category: Testing
- License: see repository
- Last updated: 2026-10-29
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add matlab/simulink-agentic-toolkit --skill simulink-use-c-function-block -g -a claude-code -y`
Codex: `npx skills add matlab/simulink-agentic-toolkit --skill simulink-use-c-function-block -g -a codex -y`
Cursor: `npx skills add matlab/simulink-agentic-toolkit --skill simulink-use-c-function-block -g -a cursor -y`
Gemini CLI: `npx skills add matlab/simulink-agentic-toolkit --skill simulink-use-c-function-block -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add matlab/simulink-agentic-toolkit`

## Description

Use when integrating legacy code, custom code, or C/C++ code into Simulink via C Function blocks. Configure Simulink C Function blocks programmatically using the SymbolSpec API. TRIGGER when the user: - Asks about calling or wrapping C/C++ code or libraries in Simulink - Wants to create, configure, or use a C Function block - Mentions integrating custom code, legacy code, or external C/C++ into a model - Asks to integrate a C++ class into a Simulink model or test bench - Mentions inputs/outputs/parameters for a C++ algorithm block

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# C Function Block Configuration

## When to Use

- Calling or wrapping C/C++ code or libraries in Simulink
- Creating, configuring, or using a C Function block
- Integrating custom code, legacy code, or external C/C++ into a model
- Integrating a C++ class into a Simulink model or test bench
- Configuring inputs, outputs, or parameters for a C++ algorithm in a block

## When NOT to Use

- Building general Simulink models without C/C++ integration
- MATLAB Function blocks (Embedded MATLAB), those use MATLAB syntax, not C/C++
- Code generation workflows (Embedded Coder, Simulink Coder), this skill is for simulation-time configuration only

## Rules

- Derive each symbol's Simulink type from the corresponding C/C++ function parameter/return type (e.g. `float` → `single`, `bool` → `boolean`, `char*`/`char[]` → `string` (R2024b+)). However, when replacing an existing block (e.g. an S-Function), use the types already on that block first, for example, what looks like `int32` from C may actually be `fixdt(1,32,3)` or another fixed-point type in the existing model.
- **MANDATORY for C++ classes:** When the user's code defines a C++ class, you MUST first attempt to declare a Persistent symbol of `Class: ClassName` and call class methods directly in the code sections (e.g. `obj.Method(args)`). If the class has an init method (not a constructor), call it in `StartCode`. Only fall back to wrapper/handler functions or opaque pointer patterns if the class approach fails to compile.
- **Prefer relative paths** for custom code files (sources, headers, libraries, search directories). Use paths relative to the model file location (e.g. `'myFunctions.h'`, `'./src/myLib.cpp'`) rather than absolute paths. This ensures portability across machines and users.

## Workflow Overview

The rest: https://github.com/matlab/simulink-agentic-toolkit/blob/HEAD/skills-catalog/simulink-modeling/simulink-use-c-function-block/SKILL.md
