How can I compile MEX Files without the mex Command?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
5 votes
Share a link to this question
Accepted Answer
7 votes
- c_mexapi_version.c - for C
- cpp_mexapi_version.cpp - for C++
- fortran_mexapi_version.F - for FORTRAN\
- MATLAB_DEFAULT_RELEASE=R2017b - for the large Array Dimensions API
- MATLAB_DEFAULT_RELEASE=R2018a - for the interleaved complex API
- Create a project and insert your MEX source files. In the release R2016b and later add to your MEX sources one version file from the directory matlab\extern\versions. These are the files to choose from:
- On the Project menu, click Properties for the project to open the property pages.
- Under C/C++ General properties, add the MATLAB® include folder, matlab\extern\include, as an additional include folder.
- Under C/C++ Preprocessor properties, add MATLAB_MEX_FILE as a preprocessor definition.
- Add one of the following macros:
- The macro MX_COMPAT_32 for the compatible array dimensions API, or
- The macro MATLAB_DEFAULT_RELEASE=R2017b for the large array dimensions API, or
- The macro MATLAB_DEFAULT_RELEASE=R2018a for interleaved complex API.
- Under Linker General properties, change the output file extension to .mexw64.
- Locate the .lib files for the compiler you are using under matlabroot\extern\lib\win64\microsoft and under Linker Input properties, add libmx.lib, libmex.lib, and libmat.lib as additional dependencies.
- Create a .def file to export the MEX entry point(s). On the Project menu, click Add New Item and select Module-Definition File (.def). Here is the .def file for the releases R2016a and before:
- Under Linker Input properties, add the module definition (.def) file you created.
- Under Linker Debugging properties, if you intend to debug the MEX file using the IDE, specify that the build generates debugging information. For more information about debugging, see Debug on Microsoft Windows Platforms.
- Set the environment variable MWROOT to the MATLAB R2018a installation root directory.
- Copy your MEX sources to the directory mysrc.
- Copy the file $MWROOT/extern/version/c_mexapi_version.c to the directory mysrc.
- Copy the following file Makefile to the directory mysrc.
4 Comments

More Answers (0)
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)