using mexaw64 in matlab code

3 次查看(过去 30 天)
Debojyoti Biswas
Debojyoti Biswas 2019-3-19
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.

回答(1 个)

Madheswaran
Madheswaran 2025-3-27
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 个评论
Walter Roberson
Walter Roberson 2025-3-27
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by