TMC: Tiny MATLAB (R) - to - C Compiler

TMC/TinyMc:  Tiny MATLAB (R) - to - C Compiler is a package that includes a command-line converter utility and  run-time support library for conversion MATLAB-written projects to  C code.


Generation C-code project from existing MATLAB code
  • Maximal portability and minimal dependencies on third-party software libraries
  • Supports migration of MEX-files (if its C code is available)
  • The generated code uses TMC run-time library
  • Flexible extension of build-in functions set
  • Supports wide MATLAB syntax subset (cell arrays, structures, 2D matrixes etc.)
  • Support of some functions (e.g. roots_qd, leftdivide_qd) implemented with quadruple-precision floating-point (128 bit float) based on quadruple-precision floating-point  compilation of CLAPACK (Fortran to C translation of LAPACK) and libquadmath library
  • An open-source project
  • Free use to produce  proprietary software 



The most updated sources are in the repository at

The main project page TMC Compiler is at  SourceForge:


All this software is an open-source:
  • Code generator. Available under GPL license.  
  • Runtime library. Available under BSD 2-Clause license.  Third Party Software used in the library may impose additional restrictions, the details may be found in the software documentation. Anyway, a user may produce a proprietary software.

    How to use this tool ?

    Start from one of code examples, it contains a script to run the conversion tool. 

    The converstion tool runs in too passes. At the first pass user provides a root function name and a list of directories where to search for other functions. The output of the first pass is a list of dependencies files that should be compiled and a file with information about number of input and output arguments of the functions that had been recognized. At the second pass all the dependencies files are converted to C-code and some additional files are generated for runtime initialization. 

    Now have a set of C files for you project. You may create the project manually or use CMake utility. Add TMC run-time support library to the project as a library or directly add its source. Build the project and that is!

    The goal of this software is to migrate from MATLAB to C, to build a compact stand-alone portable application that doesn't depend on  MATLAB run-time, port it to selected platform, and  optimize its performance. The user should locate the time-critical pieces of his code, re-write them in C and replace their m-code by MEX-files. TMC compiler to "glues" the numeric intensive calculations encapsulated in MEX with logics remained in M-files. The process may be iterative.

    TMC run-time support library

    The code generated by the compiler is linked to provided run-time support library. You may compile this library and use it in object form or simply add its code to the project, that simplifies the debugging. The library implements basic operations and a minimal subset of build-in functions. The linear algebra operations are implemented by CLAPACK code. User may extend the function set;  new function should be written in C and have predefined prototype as described in the documentation. This function is then added to the code.  


    There is no special procedure for the tool installation. You need only to unzip the package. The included examples contain scripts for the calling the convertor to generate the C-code.

    The language restrictions

    The tool does not support GUI and classes. It also implements very little set of funcctions but user may implement the functions by himself. The list of restrictions and known problems is available.


    Release 1.20 (27.10.2020):
    The latest sources and pre-compiled converter are  in GitHub repository.
     - Bugs are fixed in the support library and in converter
     - Supported (~) function output parameter
     - Added examples of usage the generated code with C#
     - Added code and example of usage with MPI interface
     - Added an example of build with CMake and JSON file parser

    The following activity is planned:
    • Improved support of 3D matrixes
    • Develop the multi-threading support

    TMC Compiler support

    For questions and any feedback please :
    - contact directly the author by e-mail:
    - visit TMC Compiler Facebook page: TMC Compiler - Tinymc - translator from restricted MATLAB to C

    Any bug reports, feedbacks and questions will be appreciated.

    See also:

     Alternative Matlab/Octave compiler discussion

    Articles and tutorials 

    Writing MATLAB to C converter: Parser and Code Generator created with Bison/Flex

    Quadruple precision floating-point calculations in C/C++/FORTRAN

    • MATLAB is a registered trademark of Mathworks Inc.
    • CVI, LabVIEW, National Instrumentsare trademarks of National Instruments Corporation.
    • Delphi is a trademark of Embarcadero Technologies (now a division of Idera)


    RussellHaley said...

    Hi! is there any correlation between the size of the matlab code and the size of the binary? I was speculating about trying to stuff some NN code from Matlab onto an embedded system, like an stm32F with 128K ram and 512K flash. (I believe the MCU has an external RAM controller for more ram but...). I know nothing about matlab and little about Neural Nets.

    Shmuel Safonov said...

    Yes, the size of the generated binary grows with size of the code. I am affraid also that needed dynamic memory size may be too large for this MCU. Such binary is sutable for Raspberry Pi with Linux or smartphone with Android.