-
Notifications
You must be signed in to change notification settings - Fork 795
mexFiles
Tomas (8ba995b) Libal edited this page Sep 7, 2015
·
1 revision
- summary A discussion of mex files in PMTK
PMTK includes a few mex files, which are Matlab interfaces to compiled c code that can be executed as though they were regular .m files. Mex files must be generated for each type of OS. Currently we have only included 32 bit linux, and windows versions. If you are using another OS, the vast majority of PMTK should still function fine. Many 'backup' .m files exist, which are called automatically if a mex version cannot be found.
If you run into problems, however, or want increased speed, you may need to compile files manually. Here are some pointers.
- Before you run the command for the first time, you need to type to tell Matlab what compiler to use. This only has to be done once per Matlab installation.
- Some versions of Matlab do not ship with a compiler. If this is the case, you can install the visual studio express 2008 C++ compiler available for free from here. Note, Matlab does not fully support the 2010 edition yet, (at least not without patches). The visual studio compiler may also generate better code than the built in Matlab lcc.
- Compiling on a 64 bit windows system requires additional setup, in particular, the windows SDK - see this page for official details. However, I had to use the instructions and files from this file exchange posting to get it to work.
- For standalone .c or .cpp files, (which do not link to other libraries), compilation is very easy. Suppose the file is called foo.c. Change to the directory containing foo.c, using , and then type .
- On newer Matlab versions, (> 2006a) you should use the switch to mex, which lets the mex file handle arrays larger than 2.^32. This is required when compiling on a 64 bit OS. For example, the above command would become
- If Matlab complains that your compiler is too new(!) see this page on downgrading gcc on ubuntu.
- Some packages found in pmtkSupport may require custom mex commands. See their documentation for details, or look for an installation script. Generally this involves linking to other source files. Simply specify the additional files to link to as in . If you need to compile a file first for inclusion in multiple mex files, use e.g. , which will create a file on linux and a file in Matlab. You can the link to these using e.g. .
- If you do generate mex files for another OS, please send them to us so that we can include them in for others to use.
- For more information on mex files, see this tutorial or read the official documentation here.
- Octave now supports mex files, (as well as their own .oct interface), but we have not yet included any. One issue is that Octave uses the same mex extension, (simply .mex) for every OS making it difficult to include them for more than one platform. A solution for the future might be to have initPmtk3 automatically rename 'archived' versions depending on the detected system. The command to compile a .c file, (written as mex interface) is the same as in Matlab, (at least from within Octave): . See this page for more details.
- In the future, we may add automatic compilation support. See the compileC.m function for an existing basic implementation. Unfortunately, the majority of the packages in pmtkSupport require custom linking commands, and so we can't simply walk over all of the .c files found, calling mex.