I am using gnumex in Matlab in Windows for setting up mex for compiling c++ code. There is a problem with setup for Cygwin which prevents me from using fopen. Hence, I installed mingw which solves the issue of fopen. But for a program which does not include fopen/fclose, I find that the performance is slower by the order of 5 in mingw when compared to cygwin. Is this behaviour expected?
Following are the gcc/g++ version used by cygwin and mingw:
D:\cygwin64\bin>gcc --version
gcc (GCC) 4.8.3
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
D:\mingw64\mingw64\bin>gcc --version
gcc (x86_64-posix-seh-rev1, Built by MinGW-W64 project) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Mingw is using a newer version of gcc. So, I would assume that it should be faster. But it is not the case.
Also, mex -v produces almost identical output when compiling the files: (the only differnce is in the LINKFLAGS. The order of -mwindows and GM_ISCPP is reversed.)
For Cygwin,
This is mex, Copyright 1984-2007 The MathWorks, Inc.
-> Default options filename found in C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b
----------------------------------------------------------------
-> Options file = C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b\mexopts.bat
MATLAB = C:\PROGRA~1\MATLAB\R2009b
-> COMPILER = gcc
-> Compiler flags:
COMPFLAGS = -c -DMATLAB_MEX_FILE -x c++
OPTIMFLAGS = -O3
DEBUGFLAGS = -g
arguments =
Name switch = -o
-> Pre-linking commands =
-> LINKER = C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\linkmex.pl
-> Link directives:
LINKFLAGS = -mwindows - LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex GM_ISCPP -mwindows
LINKDEBUGFLAGS = -g -Wl,--image-base,0x28000000\n
LINKFLAGSPOST =
Name directive = -o pnlFitness_cpp.mexw64
File link directive =
Lib. link directive =
Rsp file indicator =
-> Resource Compiler = C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\rccompile.pl -o mexversion.res
-> Resource Linker =
----------------------------------------------------------------
--> gcc -c -DMATLAB_MEX_FILE -x c++ - oC:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_FZ~1\pnlFitness_cpp.obj - IC:\PROGRA~1\MATLAB\R2009b\extern\include -IC:\PROGRA~1\MATLAB\R2009b\simulink\include -O3 -DMX_COMPAT_32 pnlFitness_cpp.cpp
--> C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\linkmex.pl -o pnlFitness_cpp.mexw64 -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex GM_ISCPP -mwindows -s C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_FZ~1\pnlFitness_cpp.obj
link command: g++ -shared C:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex\mex.def -o pnlFitness_cpp.mexw64 -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex -mwindows -s C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_FZ~1\pnlFitness_cpp.obj -llibmx -llibmex -llibmat
For Mingw,
This is mex, Copyright 1984-2007 The MathWorks, Inc.
-> Default options filename found in C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b
----------------------------------------------------------------
-> Options file = C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b\mexopts.bat
MATLAB = C:\PROGRA~1\MATLAB\R2009b
-> COMPILER = gcc
-> Compiler flags:
COMPFLAGS = -c -DMATLAB_MEX_FILE -x c++
OPTIMFLAGS = -O3
DEBUGFLAGS = -g
arguments =
Name switch = -o
-> Pre-linking commands =
-> LINKER = C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\linkmex.pl
-> Link directives:
LINKFLAGS = -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex -mwindows GM_ISCPP
LINKDEBUGFLAGS = -g -Wl,--image-base,0x28000000\n
LINKFLAGSPOST =
Name directive = -o pnlFitness_cpp.mexw64
File link directive =
Lib. link directive =
Rsp file indicator =
-> Resource Compiler = C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\rccompile.pl -o mexversion.res
-> Resource Linker =
----------------------------------------------------------------
--> gcc -c -DMATLAB_MEX_FILE -x c++ -oC:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_YK~1\pnlFitness_cpp.obj -IC:\PROGRA~1\MATLAB\R2009b\extern\include -IC:\PROGRA~1\MATLAB\R2009b\simulink\include -O3 -DMX_COMPAT_32 pnlFitness_cpp.cpp
--> C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\linkmex.pl -o pnlFitness_cpp.mexw64 -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex -mwindows GM_ISCPP -s C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_YK~1\pnlFitness_cpp.obj
link command: g++ -shared C:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex\mex.def -o pnlFitness_cpp.mexw64 -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex -mwindows -s C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_YK~1\pnlFitness_cpp.obj -llibmx -llibmex -llibmat