FAQ 009: Information about MEX Compilers  

Question

What do I need to know about MEX compilers and MEX DLLs for Simulink S-functions?

Solution

In some situations, the build process asks for a MEX compiler, for example, if there is an S-function in the Simulink model without a corresponding MEX DLL.

For more information about S-functions, refer to:

  • https://mathworks.com/help/simulink/sfg/what-is-an-s-function.html
  • https://mathworks.com/help/matlab/matlab_external/build-an-executable-mex-file.html 

S-functions are not only used to integrate user-specific C code into a Simulink model. S-functions are also generated automatically when you work with dSPACE blocksets, such as the RTI CAN MultiMessage Blockset, RTI LIN MultiMessage Blockset, Automotive Simulation Models (ASM).

For simulation in Simulink and C code generation, the S-function code must be compiled to a MEX DLL.

Generating the MEX DLL on the PC requires a compatible C/C++ compiler. Depending on the MATLAB Release, the DLL has the file name extension *.mexw64 or *.mexw32.

To set up the compiler, enter the following command in the MATLAB Command Window:

mex –setup

Selecting a Compatible MEX Compiler for MATLAB 64-Bit

As of Release 2017-B, dSPACE RCP and HIL (64-bit) software supports the following C/C++ compilers for building MATLAB MEX functions:

  • MinGW (GNU Compilers Collection)
    • GCC 4.9.2: MATLAB R2016a, R2016b, and R2017a
    • GCC 5.3.0: MATLAB R2017b and R2018a
    • GCC 6.3.0: MATLAB R2018b to MATLAB R2023a
    • GCC 8.1.0: since MATLAB R2023b
  • Microsoft Visual Studio
    • Microsoft Visual Studio 2015 Professional: dSPACE Release 2019-A and dSPACE Release 2019-B
    • Microsoft Visual Studio 2017 Professional: dSPACE Release 2020-A, dSPACE Release 2020-B, and dSPACE Release 2021-A
    • Microsoft Visual Studio 2019 Professional: dSPACE Release 2021-B, dSPACE Release 2022-A, dSPACE Release 2022-B, dSPACE Release 2023-A
    • Microsoft Visual Studio 2022 Professional: dSPACE Release 2023-B, dSPACE Release 2024-A, dSPACE Release 2024-B, dSPACE Release 2025-A, dSPACE Release 2025-B, dSPACE Release 2026-A

Up to and including Release 2017-A, dSPACE RCP and HIL (64-bit) software supports only Microsoft Windows SDK 7.1 for building MEX functions. This is also valid if you use Windows 10.

Selecting a Compatible MEX Compiler for MATLAB 32-Bit

32-bit MATLAB versions include the LCC compiler that can be used as the MEX compiler in most cases.

Note

The MEX compiler is not the same compiler that is used for building complete applications with the dSPACE environment.
 

Tags

Date 2025-10-13
Software Type Implementation Software
Product ConfigurationDesk, RTI (Real-Time Interface)
Information Type Frequently Asked Questions
Information Category Getting Started
Keywords MEX compilers, S-Functions, RTICANMM, RTILINMM

Stay up-to-date with our dSPACE direct newsletter service.

With our dSPACE newsletter service, we will keep you informed about current use cases and new solutions and products, as well as trainings and events. Sign up here for a free subscription.

Enable form call

At this point, an input form from Click Dimensions is integrated. This enables us to process your newsletter subscription. The form is currently hidden due to your privacy settings for our website.

External input form

By activating the input form, you consent to personal data being transmitted to Click Dimensions within the EU, in the USA, Canada or Australia. More on this in our privacy policy.