AmesimKnowledge

Community Knowledge > Co-Simulation & Integration

Amesim-Simulink S-Function/Mex Interface: Compilation and Path Issues

Beyond FMU/FMI-based co-simulation, Amesim also interfaces with Simulink via a generated S-function/mex cosimulation block (the older/native "AME cosim" interface, e.g., via sl2amecosim). This interface has its own distinct class of practical failures, gathered from MATLAB Central threads and Siemens community forum titles.

Version compatibility between Amesim and MATLAB/Simulink releases

A recurring theme: the Amesim/Simulink cosim interface is only validated against specific MATLAB release ranges per Amesim version. Example reported in a community search summary: Amesim 15 was only tested up to Simulink 2016a, while Amesim 15.2 compiles for cosim with MATLAB 2016b and 2017a. Practical implication: if the Amesim-Simulink interface fails to compile after a MATLAB upgrade, check the supported MATLAB version matrix for your specific Amesim release before assuming a configuration bug — either upgrade Amesim or pin MATLAB to a compatible release.

Missing ASU_sf.h header file

A specific, well-documented failure when building the Simulink-side S-function that talks to an Amesim cosim model:

"ASU_sf.h": No such file or directory

This occurred on MATLAB R2018a/2018b with Amesim 2019.2 while running the sl2amecosim command. Confusingly, the user reported the file was physically present in the folder — the real problem was that MATLAB's build process wasn't searching that folder for headers.

Fix: add the directory containing ASU_sf.h to MATLAB's search path before invoking the command:

addpath('path_to_directory_containing_ASU_sf_header');

Then retry sl2amecosim. This is a MATLAB path-configuration issue, not an Amesim installation problem — worth checking before reinstalling anything.

Source: Unable to generate .dll file of simulink model to be used in amesim using the command sl2amecosim – MATLAB Answers

Directory-nesting sensitivity in the compiled mex cosim block

A more subtle and apparently unresolved issue: an Amesim-generated .mexw64 cosimulation block works fine in Simulink when both the Simulink model and the Amesim model file sit in MATLAB's current working directory, but fails when the model is moved one folder level deeper, with the error:

"Error in 'PlantModel/S-Function' while executing C MEX S-function 'PlantModel_', (mdlInitializeConditions), at time 0.0. Caused by: Simcenter Amesim mexfunction PlantModel_ did an abnormal exit!"

No permanent fix was found in the MATLAB Central discussion — only workarounds:

  1. Change MATLAB's current working directory to match the folder containing the Amesim model, or
  2. Move the Amesim model file itself up into the working directory (flatten the folder structure).

The likely underlying cause (per the discussion, not officially confirmed) is that the generated mex function relies on relative path assumptions that break once the file layout changes. Practical implication for KB users: keep Amesim cosim model files and their calling Simulink model in the same flat working directory rather than organizing them into subfolders, unless/until you've specifically tested that your folder layout doesn't trigger this failure.

Source: mex function co-simulation directory error – MATLAB Answers

Environment variable checks specific to this interface

Consistent with other Amesim integration failures documented in this KB, community answers repeatedly point back to the same root cause checklist for S-function/cosim compilation failures:

  • Confirm the AME environment variable is set correctly to the Amesim installation folder.
  • If models compile fine standalone (via Amesim's own Visual compiler) but fail specifically when the Simulink interface block is involved, check that a MATLAB environment variable is also set and points at a valid MATLAB installation — this is a distinct variable from AME and easy to overlook since it's only needed for the cosim-interface build path.

Practical checklist for Amesim-Simulink S-function cosim build failures

  1. Check the Amesim-version-to-MATLAB-version compatibility matrix before assuming a bug.
  2. If a header file "can't be found" despite being present, check/add the relevant directory to MATLAB's path (addpath) rather than assuming file corruption.
  3. Keep the Simulink model and Amesim cosim model file(s) in the same flat directory (current working directory) rather than nested subfolders.
  4. Verify both AME and MATLAB environment variables are set, especially when the failure is specific to the Simulink-interface build path and not to plain Amesim compilation.

Source: https://www.mathworks.com/matlabcentral/answers/418557-mex-function-co-simulation-directory-error · retrieved 2026-07-08