I'm building levmar on my Windows machine and it builds well with Visual C++ 2012 using the existing Makefile that is bundled with levmar package. But I have some problems building the Mex files of Matlab interface for levmar. The problem seems to be because I'm building it with the old lcc compiler, and my Matlab is R2008a, which is pretty outdated.
Unfortunately the latest Microsoft compiler that Matlab R2008a can support is Microsoft Visual C++ 2008. Therefore, I'm looking for a way to make my MATLAB works with Visual C++ 2012. And I found the following steps. Hope this is useful for other people as well.
1. Run mex -setup in MATLAB R2008a.
When the prompt "Would you like mex to locate installed compilers [y]/n? " appears, say No, and select the latest Visual C++ version in the list. Mine is Microsoft Visual C++ 2008.
The purpose in the above step is to let Matlab copy the mexopts.bat into %Appdata%\MathWorks\MATLAB\R2008a folder so we can make modifications on it to make Visual C++ 2012 recognized by Matlab.
2. Navigate to %Appdata%\MathWorks\MATLAB\R2008a. Locate mexopts.bat and open it using Notepad or Notepad++.
For example, on my machine it is C:\Users\Son\AppData\Roaming\MathWorks\MATLAB\R2008a.
3. Look for VS90COMNTOOLS and modify it into VS110COMNTOOLS. This is an environment variable that specifies the installation folder of Visual Studio 2012 (version 11.0).
4. Change the LINKERDIR to
set LINKERDIR=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A
On your machine you might want to change it accordingly to the Microsoft SDKs folder that contains Bin, Lib, and Include folder, where the Lib folder contains kernel32.lib.
5. Save your mexopts.bat and you are done. Try compiling some Mex files in MATLAB R2008a to make sure it works.
6. Backup your modifed mexopts.bat so next time you accidentally execute mex -setup and the mexopts.bat in the AppData\Roaming\MathWorks folder is overwritten, you have it ready for restore.