This discussion is a bit old, but I thought I'd add to it with what I've recently learned. If you follow the instructions in Matlab's documentation (
http://www.mathworks.com/help/matlab/matlab_external/compiling-mex-files-with-the-microsoft-visual-c-ide.html) you can work entirely in VS 2013. Below are some notes I put together as I set this up. The end result is a VS 2013 project file in which you can compile directly to a .mexw64 file without having to jump through some of the hoops I described earlier.
When setting Configuration Properties, make sure the
Configuration being set is “All Configurations”. Also feel free to delete configurations you
will not use.
- Copy helloworld_vs2013.sln,
helloworld_vs2013.vcxproj, and helloworld.cpp to a new directory.
- Open it helloworld_vs2013.sln.
- Rename the helloworld project entry in Solution
Explorer to deconvLR_AF_VS
- Right-click this project and go to Configuration
Properties|General|Configuration Type and change it from Application (.exe) to
Dynamic library (.dll). Click Apply.
-
Remove the helloworld entry in the Solution
Explorer since we’re not using helloworld.cpp.
- Add deconvLR_mex.cpp and deconvLR_mex.h to the
project
- Under Configuration Properties|C/C++|General add
$(MATLAB_PATH)\extern\include
- Right-click the deconvLR_AF_VS project and click
Add New Item. Select Visual
C++|Code|Module-Definition File (.def).
Name the file deconvLR_AF_VS.def.
- Make the contents of this DEF file:
LIBRARY
DECONVLR_AF_VS EXPORTS mexFunction
10.
Under C/C++ Preprocessor properties, add
MATLAB_MEX_FILE as a preprocessor definition.
11.
Under Linker|General, add
$(MATLAB_PATH)\extern\lib\win64\microsoft to the Additional Library Directories
12.
Under Linker|Input, make sure the Modulate
Definition File (deconvLR_AF_VS.def) is present.
13.
Under Linkers|Input add libmx.lib, libmex.lib,
and libmat.lib to Additional Dependencies.
14.
Under Configuration Properties|General change Target
Extension from .dll to .mexw64. Make sure this is done for “All Configurations”.
15.
When you build the solution, you will see a
CUDA\deconvLR_AF_VS.mexw64 file now exists.
The build process also copied nvvm64_30_0.dll (the CUDA DLL file) into
this directory.
This file needs to
either be on the Windows path or in the same directory as the .mexw64
file.
Otherwise an error saying that the
specified module cannot be found will be returned when trying to use the mex
file in Matlab.
Debugging:
Note that you can use clear
mex in Matlab to free up the MEX file.
1. Change the Configuration Type to CUDA_Debug
2. Build the solution.
Note that _debug is appended to the root of
the filename.
You need to make sure your
Matlab code calls
this .mexw64, not
the other.
3.
Add breakpoints in VS2013 where you want.
4.
Go to Debug|Attach to Process to attach to
Matlab.
5.
Call the function under test and you should stop
at the breakpoint.