using mexaw64 in matlab code

1 view (last 30 days)
Debojyoti Biswas
Debojyoti Biswas on 19 Mar 2019
Commented: Walter Roberson on 27 Mar 2025
Hello,
I am new to Matlab. I have a code segment which works in ubuntu and mac computers.I need that to work in windows.
I think I need to change the following code segment so that it can work with mexw64.
if strcmp(mx,'mexa64')
cc = 'CC=gcc';
cflags = ['CFLAGS=-fPIC -fno-omit-frame-pointer -std=c99 -O3 ' ...
'-D_GNU_SOURCE -pthread -fexceptions '];
mex('-silent','-largeArrayDims',cc,[cflags define], ...
include{:},link{:},source{:});
elseif strcmp(mx,'mexmaci64')
cflags = 'CFLAGS= -std=c99 ';
mex('-silent','-largeArrayDims',[cflags define], ...
include{:},link{:},source{:});
else
error(['Platform not yet supported. Your MEX file extension is ' ...
mx '. Please edit mexmake_nsm.m to allow for this extension.']);
end
But I have no idea about the input arguments. Any hekp would be highly appreciated.

Answers (1)

Madheswaran
Madheswaran on 27 Mar 2025
You can extend your code to support Windows as well. Consider the below code sinppet:
% Compile based on platform
if strcmp(mx,'mexa64')
% ... Your existing code ...
elseif strcmp(mx,'mexmaci64')
% ... Your existing code ...
elseif strcmp(mx,'mexw64') % Windows file extention for mex files is 'mexw64'
cflags = 'CFLAGS=-std=c99 -O3';
mex('-silent','-largeArrayDims', cc,[cflags define], ...
include{:},link{:},source{:});
else
error(['Platform not yet supported. Your MEX file extension is ' ...
mx '. Please edit mexmake_nsm.m to allow for this extension.']);
end
I have added a condition for 'mexw64' which is the Windows MEX file and set appropriate compiler flags for Windows with MinGW. This assumes you're using MinGW as your C compiler on Windows. You can verify your current compiler setup with 'mex -setup C'. If you're using a different compiler, you might need to adjust the flags accordingly. See the list of supported compilers here: https://mathworks.com/support/requirements/supported-compilers.html
For more information on MEX command and its options, refer to the following documentation: https://mathworks.com/help/matlab/ref/mex.html
Hope it helps!
  1 Comment
Walter Roberson
Walter Roberson on 27 Mar 2025
Note, however, that if you have a configuration file that supports Linux and (Intel) Mac, then there is the possibility that the accompanying C or C++ code might include portions that are Linux or MacOS or Unix specific. If so, the work needed to adjust the code might be anywhere from "fairly easy" to "quite difficult" depending on what the OS-specific parts are.

Sign in to comment.

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!