Search code examples
matlabmexcompiler-options

error with the mex command -g (no optimization)


I am trying to mex a file in a script. The C file which has to be mexed is generated in one of the previous steps of the script before it is mexed.

When I use the below line in the script, everything works fine and the script runs successfully.

mex (strcat(component_name,'_s_func','.c'));

but when I add the same line below with

mex -g (strcat(component_name,'_s_func','.c'));

it gives me the error

C:\PROGRA~2\MATLAB~1\BIN\MEX.PL: Error: '(strcat(component_name,_s_func,.c))' not found.

Any idea why its not able to find the same file while using -g while it can find it when using without -g option?


Solution

  • The problem with your statement is that with the syntax

    mex -g [...]
    

    MATLAB assumes you are calling mex with the string arguments '-g' and '[...]' so it assumes that your file is called (strcat(component_name,'_s_func','.c')) and does not execute the command.

    You can either use the solution you posted with eval, as that way you again call it with the strings '-g' and 'filename.c'. Another possibility would be to use the syntax

    mex('-g',strcat(component_name,'_s_func','.c'));
    

    because that way the command strcat is really executed before calling mex.

    --

    This is the same behavior as e.g. with clear. As you might know, the following statements are equal:

    clear a b c
    clear('a','b','c');