MATLAB Answers

Determining selected MEX compiler inside m-Function running in Simulink

2 views (last 30 days)
Dan Harris
Dan Harris on 27 Jun 2018
Commented: Dan Harris on 3 Jul 2018
I am attempting to determine the active MEX compiler inside a MATLAB function that is called by a MATLAB function block in Simulink. I need to do this because this function also calls an external library and depending on what compiler is selected, my function needs to source the correct version of the shared library for use. I have tried the following in my code:
coder.extrinsic('mex.getCompilerConfigurations');
comp_C.ShortName = ' ';
comp_CPP.ShortName = ' ';
comp_C_info = ' ';
comp_CPP_info = ' ';
comp_C=coder.const(mex.getCompilerConfigurations('C','Selected'));
comp_CPP=coder.const(mex.getCompilerConfigurations('C++','Selected'));
comp_C_info=comp_C.ShortName;
comp_CPP_info=comp_CPP.ShortName;
if contains(comp_C_info,'mingw64') && ...
contains(comp_CPP_info,'mingw64-g++')
comp = 1;%minGW
elseif contains(comp_C_info,'MSVC') && ...
contains(comp_CPP_info,'MSVCPP')
comp = 2;%Visual Studio
end
The error I receive back is:
This 'mex.CompilerConfiguration' constant could not be eliminated.
Function 'foo.m' (#65.46734.46781), line 924, column 26:
"mex.getCompilerConfigurations('C++','Selected')"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
This 'mex.CompilerConfiguration' constant could not be eliminated.
Function 'foo.m' (#65.46661.46706), line 923, column 24:
"mex.getCompilerConfigurations('C','Selected')"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
If my method is correct, how do I correct this error? If not, what is the better way to identify the active MEX compiler, in this context?
Thanks!!!

  0 Comments

Sign in to comment.

Accepted Answer

Jon Lobo
Jon Lobo on 3 Jul 2018
Hi Dan,
I recommend putting this in a model callback rather than in a MATLAB function block. This can execute before the start of your model is in a good spot to figure out which compilers are available rather than in the simulation phase.

More Answers (0)


Translated by