c - Use GCC as the Default MEX Compiler for MATLAB 2014a on a 64 bit Windows 7 machine -
c - Use GCC as the Default MEX Compiler for MATLAB 2014a on a 64 bit Windows 7 machine -
i looking simple way compile unix mex files on windows 7 computer.
the mex files compile smoothly in matlab 2014a on mac os x 10.9 (using "xcode clang" compiler). of people work with, however, having problem compiling them in windows 7 using c compiler windows 7.1 sdk.
i understand might able avoid these errors if utilize gcc compile mex files in matlab. wondering if knows how. happy download , edit whatever files necessary can a) compile mex files within matlab using "mex" command , b) guarantee "-i" , "-l" instructions passed mex compiler.
note, issue similar to post 2+ years ago. said, have set new post since a) matlab/mingw/mex have had important updates since (not sure if mingw easiest way out of mess); b) there 64 bit thing (not sure if it's problem) , c) "-i" , "-l" options important.
start downloading mingw-w64 compiler toolchain. we'll using x64 version. here's link latest binaries of moment (gnu gcc 4.9.1).
extract 7z archive location (preferably without spaces), c:\mingw-w64\mingw64
.
add bin
folder path environment variable, set path=c:\mingw-w64\mingw64\bin;%path%
system-wide.
create next file (feel free add together compiler switches -std=c++11
if want c++11 support):
@echo off set matlab=%matlab% set mw_target_arch=win64 set mingwroot=c:\mingw-w64\mingw64 set path=%mingwroot%\bin;%path% set compiler=x86_64-w64-mingw32-g++ set compflags=-c -m64 -mwin32 -mdll -wall -dmatlab_mex_file set optimflags=-dndebug -o2 set debugflags=-g set name_object=-o set linker=x86_64-w64-mingw32-g++ set libloc=%matlab%\extern\lib\%mw_target_arch%\microsoft set linkflags=-shared -l"%libloc%" -l"%matlab%\bin\%mw_target_arch%" set linkflagspost=-lmx -lmex -lmat set linkoptimflags=-o2 set linkdebugflags=-g set link_file= set link_lib= set name_output=-o "%outdir%%mex_name%%mex_ext%" set rc_compiler= set rc_linker=
now utilize compile sample mex-file:
>> mex -f mexopts_mingw64.bat -v -largearraydims "c:\program files\matlab\r2014a\extern\examples\mex\yprime.c" >> yprime(1,1:4) ans = 2.0000 8.9685 4.0000 -1.0947
note: if compiling c++ code , want distribute binaries other people, might need include couple of dll files mingw dependencies compiled mex-file (stuff libstdc++). utilize dependency walker tool list them all.
c windows matlab gcc mex
Comments
Post a Comment