using mexaw64 in matlab code

7 ビュー (過去 30 日間)
Debojyoti Biswas
Debojyoti Biswas 2019 年 3 月 19 日
コメント済み: Walter Roberson 2025 年 3 月 27 日
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 Center および File ExchangeWrite 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