Skip to content

Instantly share code, notes, and snippets.

@MVoz
Forked from dgleich/mexopts.bat
Created April 27, 2018 22:56
Show Gist options
  • Save MVoz/0bb451704fe1952964857128c84c50b2 to your computer and use it in GitHub Desktop.
Save MVoz/0bb451704fe1952964857128c84c50b2 to your computer and use it in GitHub Desktop.
Mex opts file for mingw64 for C and C++
@echo off
rem MSSDK71OPTS.BAT
rem
rem Compile and link options used for building MEX-files
rem using the Microsoft Windows Software Development Kit.
rem
rem $Revision: 1.1.6.2 $ $Date: 2011/03/09 05:35:27 $
rem Copyright 2010 The MathWorks, Inc.
rem
rem StorageVersion: 1.0
rem C++keyFileName: MSSDK71OPTS.BAT
rem C++keyName: Microsoft SDK
rem C++keyManufacturer: Microsoft
rem C++keyVersion: 7.1
rem C++keyLanguage: C++
rem
rem ********************************************************************
rem General parameters
rem ********************************************************************@echo off
rem Compile and link options used for building MEX-files using Cygwin,
rem for the 64-bit version of MATLAB.
rem
rem It makes the assumption that you installed Cygwin in C:\CYGWIN,
rem and that you installed either the "mingw64-x86_64-gcc" package.
rem
rem This file should be renamed to "mexopts.bat" and copied to:
rem C:\Documents and Settings\<Username>\Application Data\MathWorks\MATLAB\<MATLAB version>\
rem
rem This file only supports C code. It can easily be changed to compile C++
rem code by replacing "gcc" by "g++" in COMPILER and LINKER, and by adding
rem "-static-libstdc++" to LINKFLAGS.
rem You will also need the "mingw64-x86_64-gcc-g++" package.
rem
rem Initial version by Michel Juillard, revised by Sebastien Villemot.
rem Copyright (C) 2009-2010 Dynare Team
rem
rem This file is part of Dynare.
rem
rem Dynare is free software: you can redistribute it and/or modify
rem it under the terms of the GNU General Public License as published by
rem the Free Software Foundation, either version 3 of the License, or
rem (at your option) any later version.
rem
rem Dynare is distributed in the hope that it will be useful,
rem but WITHOUT ANY WARRANTY; without even the implied warranty of
rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
rem GNU General Public License for more details.
rem
rem You should have received a copy of the GNU General Public License
rem along with Dynare. If not, see <http://www.gnu.org/licenses/>.
rem ********************************************************************
rem General parameters
rem ********************************************************************
set MATLAB=%MATLAB%
set PATH=%PATH%;c:\cygwin\bin
set MW_TARGET_ARCH=win64
rem ********************************************************************
rem Compiler parameters
rem ********************************************************************
set COMPILER=x86_64-w64-mingw32-gcc
set COMPFLAGS=-c -fexceptions "-I%MATLAB%\extern\include"
set OPTIMFLAGS=-O3
set DEBUGFLAGS=-g -Wall
set NAME_OBJECT=-o
rem ********************************************************************
rem Linker parameters
rem ********************************************************************
set PRELINK_CMDS1=echo EXPORTS > mex.def & echo mexFunction >> mex.def
set LIBLOC="%MATLAB%\bin\win64"
set LINKER=x86_64-w64-mingw32-gcc
set LINKFLAGS= -static-libgcc -shared mex.def -L%LIBLOC%
set LINKFLAGSPOST= -lmex -lmx -lmwlapack -lmwblas -lstdc++
set LINKOPTIMFLAGS=-O3
set LINKDEBUGFLAGS= -g -Wall
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
set RSP_FILE_INDICATOR=
set POSTLINK_CMDS1=del mex.def
@MVoz
Copy link
Author

MVoz commented Apr 27, 2018

@echo off
rem MSVC110OPTS.BAT
rem
rem Compile and link options used for building MEX-files
rem using the Microsoft Visual C++ compiler version 11.0
rem
rem $Revision: 1.1.6.1 $ $Date: 2012/09/25 18:20:03 $
rem Copyright 2007-2012 The MathWorks, Inc.
rem
rem StorageVersion: 1.0
rem C++keyFileName: MSVC110OPTS.BAT
rem C++keyName: Microsoft Visual C++ 2012
rem C++keyManufacturer: Microsoft
rem C++keyVersion: 11.0
rem C++keyLanguage: C++
rem C++keyLinkerName: Microsoft Visual C++ 2012
rem C++keyLinkerVer: 11.0
rem
rem ********************************************************************
rem General parameters
rem ********************************************************************

set MATLAB=%MATLAB%
set VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 11.0
set VCINSTALLDIR=%VSINSTALLDIR%\VC
rem In this case, LINKERDIR is being used to specify the location of the SDK
set LINKERDIR=C:\Program Files (x86)\Windows Kits\8.0
set PATH=%VCINSTALLDIR%\bin;%VCINSTALLDIR%\VCPackages;%VSINSTALLDIR%\Common7\IDE;%VSINSTALLDIR%\Common7\Tools;%LINKERDIR%\bin\x86;%LINKERDIR%\bin;%MATLAB_BIN%;%PATH%
set INCLUDE=%VCINSTALLDIR%\INCLUDE;%VCINSTALLDIR%\ATLMFC\INCLUDE;%LINKERDIR%\include\um;%LINKERDIR%\include\shared;%LINKERDIR%\include\winrt;%INCLUDE%
set LIB=%VCINSTALLDIR%\LIB;%VCINSTALLDIR%\ATLMFC\LIB;%LINKERDIR%\lib\win8\um\x86;%MATLAB%\extern\lib\win32;%LIB%
set MW_TARGET_ARCH=win32

rem ********************************************************************
rem Compiler parameters
rem ********************************************************************
set COMPILER=cl
set COMPFLAGS=/c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD
set OPTIMFLAGS=/O2 /Oy- /DNDEBUG /openmp
set DEBUGFLAGS=/Z7
set NAME_OBJECT=/Fo

rem ********************************************************************
rem Linker parameters
rem ********************************************************************
set LIBLOC=%MATLAB%\extern\lib\win32\microsoft
set LINKER=link
set LINKFLAGS=/dll /export:%ENTRYPOINT% /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"%LIB_NAME%.x" /MAP:"%OUTDIR%%MEX_NAME%%MEX_EXT%.map"
set LINKOPTIMFLAGS=
set LINKDEBUGFLAGS=/debug /PDB:"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb"
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=/out:"%OUTDIR%%MEX_NAME%%MEX_EXT%"
set RSP_FILE_INDICATOR=@

rem ********************************************************************
rem Resource compiler parameters
rem ********************************************************************
set RC_COMPILER=rc /fo "%OUTDIR%mexversion.res"
set RC_LINKER=

set POSTLINK_CMDS=del "%LIB_NAME%.x" "%LIB_NAME%.exp"
set POSTLINK_CMDS1=mt -outputresource:"%OUTDIR%%MEX_NAME%%MEX_EXT%;2" -manifest "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest"
set POSTLINK_CMDS2=del "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest"
set POSTLINK_CMDS3=del "%OUTDIR%%MEX_NAME%%MEX_EXT%.map"

@MVoz
Copy link
Author

MVoz commented Apr 27, 2018

mingw_mexopts.bat

@echo off

set MATLAB=%MATLAB%
set MW_TARGET_ARCH=win64
set PATH=C:\MinGW-w64\mingw64\bin;%PATH%

set COMPILER=x86_64-w64-mingw32-g++
set COMPFLAGS=-c -m64 -mwin32 -mdll -Wall -std=c++11 -DMATLAB_MEX_FILE
set OPTIMFLAGS=-DNDEBUG -O2
set DEBUGFLAGS=-g
set NAME_OBJECT=-o

set LINKER=x86_64-w64-mingw32-g++
set LINKFLAGS=-shared -L"%MATLAB%\extern\lib\win64\microsoft" -L"%MATLAB%\bin\win64"
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%"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment