How to internally call function in executable created using MATLAB compiler (MCC) with multiple M function files?

28 views Asked by At

mcc can have multiple M files and even MAT files as input when building an executable (command prompt only, my OS is Linux).

According to the documentation the first M file is always regarded as the entrypoint for the executable. I have conducted simple compilation test with a single M file so far and it works.

Now I need to add multiple M files.

  • Original M file - this file contains a function (e.g. functionXYZ(a1, a2, a3))

  • Wrapper M file - this is a wrapper function (e.g. functionXYZWrapper(workspace)), which represents the entrypoint of the executable, loads the workspace with the arguments required by the original function, calls it and returns its value(s). It is generated automatically and has the following format:

    function res = functionXYZWrapper(workspace)
      load(workspace);
      res = functionXYZ(a1, a2, a3);
    end
    

The problem is that once I run run_functionXYZWrapper.sh, which I generated by doing

mcc -mv tests/functionXYZ/functionXYZWrapper.m functionXYZ.m 

inside my CI job I receive the following error when I download and run the artifacts from that job:

user$~: ./run_functionXYZWrapper.sh /usr/local/MATLAB/R2018a/ ../test.mat 
------------------------------------------
Setting up environment variables
---
LD_LIBRARY_PATH is .:/usr/local/MATLAB/R2018a//runtime/glnxa64:/usr/local/MATLAB/R2018a//bin/glnxa64:/usr/local/MATLAB/R2018a//sys/os/glnxa64:/usr/local/MATLAB/R2018a//sys/opengl/lib/glnxa64
Cannot find an exact (case-sensitive) match for 'functionXYZ'

The closest match is: functionXYZ in /home/user/.mcrCache9.4/getMid1/functionXYZ.m


Error in functionXYZWrapper (line 3)

MATLAB:dispatcher:InexactCaseMatch

I am very new to MATLAB and don't really plan on getting into it. All I would like to do is setup the CI pipeline.

NOTE: I do know that mcc allows the binding of MAT files when generating the executable. However, there are multiple reasons why I would not like to do that, e.g.

  • Testing will require changing the original footprint of the function to be able to load the MAT file, meaning that I will have to do something very similar to the wrapper but actually change the original source I am trying to automate the testing for
  • Each test would require MCC to be called and to build one executable per test instead of building one wrapper and then dynamically loading different MAT files accordingly
  • Each test would require a separate image with MCR to be built (in case containers are used for a clean environment) and loaded into a container. While I can and even have a base image, that has MCR installed, it would still increase the load of the CI pipeline
1

There are 1 answers

0
rbaleksandar On

It works. The problem was a small typo in the function call inside the wrapper, e.g. functionxYZ(...) instead of functionXYZ(...).