cmd="GCC='/usr/bin/gcc-11' -I/usr/local/include -L/usr/local/lib -lsundials_cvode -lsundials_nvecserial -lm ";
CAUTION: AIR CODE! Don't have mex compiler installed at the moment so can't do a hard test.
The problem in your attempt is mex command is one long string, not a set of independent input parameters so separating the arguments with commas isn't correct synatax. Then, you enclosed your filename in quotes so it became a fixed constant, not substituting in the variable name.
The above takes all the command line fixed arguments and then adds the input file name as one long string; then calls mex as a function with that long commnd line. I did test that mex() will accept the string variable by running
mex(cmd)
MEX Compile MEX-function
Usage:
mex [options ...] file [files ...]
Description:
MEX compiles and links source files into a shared library called a
MEX-file, executable from within MATLAB. It also builds executable
files for standalone MATLAB engine and MAT-file applications.
Command Line Options Available on All Platforms:
-c
Compile only. Creates an object file but not a MEX-file.
-client engine
Build standalone MATLAB engine or MAT-file application.
-compatibleArrayDims
Build a MEX-file using the MATLAB Version 7.2 array-handling
API, which limits arrays to 2^31-1 elements.
-D<name>
Define a symbol name to the C preprocessor. Equivalent to a
"#define <name>" directive in the source. Do not add a space
after this switch.
-D<name>=<value>
Define a symbol name and value to the C preprocessor. Equivalent
to a "#define <name> <value>" directive in the source. Do not
add a space after this switch.
-f <optionsfile>
For advanced users. Specify location and name of the MEX
configuration file to use. Overrides MEX's default compiler
selection mechanism.
-g
Adds symbolic information and disables optimizing built object code.
Use for debugging.
-h[elp]
Display this message.
-I<pathname>
Add <pathname> to the list of directories to search for #include
files. Do not add a space after this switch.
-l<name>
Link with object library. On Windows, <name> expands to
"<name>.lib" or "lib<name>.lib". On Linux, to "lib<name>.so".
On Mac, to "lib<name>.dylib". Do not add a space after this
switch.
-L<folder>
Add <folder> to the list of folders to search for
libraries specified with the -l option. Do not add a space
after this switch.
-largeArrayDims
Build a MEX-file using the MATLAB large-array-handling API.
This API can handle arrays with more than 2^31-1 elements when
compiled on 64-bit platforms.
-R2017b
Build a MEX-file using the MATLAB large-array-handling, and
graphics-objects APIs. This option is available on 64-bit
platforms. The API can handle arrays with more than
2^31-1 elements. -R2017b is the default option.
-R2018a
Build a MEX-file using the MATLAB large-array-handling,
graphics-objects, and interleaved-complex APIs. This option
is available on 64-bit platforms. The API can handle arrays
with more than 2^31-1 elements, and supports type-safe and
interleaved complex data access.
-n
No execute mode. Display commands that MEX would otherwise
have executed, but do not actually execute any of them.
-O
Optimizes the object code. Use this option to compile with optimization.
Optimization is enabled by default. Specify this option with the
capital letter O.
-outdir <dirname>
Place all output files in folder <dirname>.
-output <resultname>
Create MEX-file named <resultname>. The appropriate MEX-file
extension is automatically appended. Overrides MEX's default
MEX-file naming mechanism.
-setup <lang>
Change the default compiler to build <lang> language MEX-files.
When this option is specified, no other command line
input is accepted.
-silent
Suppress informational messages. The mex function still reports
errors and warnings, even when you specify -silent.
-U<name>
Remove any initial definition of the C preprocessor symbol
<name>. (Inverse of the -D option.) Do not add a space after
this switch.
-v
Verbose mode. Display the values for important internal
variables after all command line arguments are considered.
Displays each compile step and final link step fully evaluated.
<name>=<value>
Override default setting for variable <name>. This option is
processed after all command line arguments are considered.
Command Line Options Available Only on Windows Platforms:
@<rspfile>
Include contents of the text file <rspfile> as command line
arguments to MEX.
For more information, see
http://www.mathworks.com/help/matlab/ref/mex.html
which shows mex was called with the passed argument string.
Use as