Code covered by the BSD License  

5.0 | 2 ratings Rate this file 22 Downloads (last 30 days) File Size: 1.5 KB File ID: #38720 Version: 1.2

MS Visual Studio property sheet for building MEX function


Kesh Ikuma (view profile)


22 Oct 2012 (Updated )

Using Property Sheet to make VS project configuration easy

| Watch this File

File Information

Note: This solution works to develop MEX functions with Visual Studio 2012 (which is not supported by 'mex' prior to 2013A release)

As outlined by Mathworks ( MEX functions can be developed in Visual Studio (or Visual C++). Setting up a VS project for each and every MEX function (and maintaining the projects' integrity over biyearly MATLAB updates) quickly becomes cumbersome. Visual Studio's Property Sheet feature gives us an easy way to keep all MEX project settings in one place.

Matlab_Mex_Build.props contains all the configurations necessary to make a DLL project into MEX project. Follow "How to create a MEX project in VS" below for the usage, and read "How to change MATLAB paths" below to set newly created macro "MatlabExternDir".

How to create a new MEX project in VS:
1. Create an empty C++ Win32 DLL project.
2. Go to Property Manager (accessible from View menu or behind Solution Explorer tab)
3. Right click on the created project name, click on "Add Existing Property Sheet...". In the dialog window, choose the downloaded and unzipped "Matlab_Mex_Build.props"
4. Add a source code file to the project and begin programming!

How to change MATLAB paths:
1. Open "Matlab_Mex_Build.props" in a text editor (recommend VS as it gives you XML color coding)
2. Look for <MatlabExternDir>. There are 2 in the file: one for Win32 and another for x64. Modify the applicable MatlabExternDir according to the installed Matlab version (or both if you have both 32- and 64-bit versions of MATLAB installed)

MATLAB release MATLAB 8.0 (R2012b)
Other requirements Microsoft Visual Studio
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
18 Feb 2015 Arash Salarian  
30 Jan 2015 Kesh Ikuma

Kesh Ikuma (view profile)

@Hamid - I cannot help you with the earlier VS property sheet format (.vsprops) as I have never dealt with it myself. My best suggestion is to create a new property sheet, set a few compiler and linker options and see if you can determine the difference between vsprops and props format. Both formats are in XML, so you can view them in a text editor. Good luck.

Comment only
29 Jan 2015 Hamid Ramezani


I have VS2008. It only recognise *.vsprops. Howevere, When I try to add "Matlab_Mex_Build.props" a window pops up which says it cannot add property sheet. Could you please help me.


24 Oct 2012 1.2

Edited "General Information" text

Contact us