Compiling Cuda mex files with Visual Studio 2013

Configuration: Matlab 2015b, Visual Studio 2013, Intel 64bit machine.

In Visual Studio do the following:
1) File -> New Project; Select location and name; in the project type, select NVIDIA -> CUDA 8.0 (choose your CUDA version as appropriate);

2) Project -> Properties -> Configuration Manager -> Active Solution Platform -> choose x64;

3) Project -> Properties -> Configuration -> Release (possibly optional);

4) Project -> Properties -> Configuration Properties -> CUDA C/C++ -> Device -> Code Generation -> compute_35, sm_35 (choose as appropriate according to your card’s compute capability);

5) Project -> Properties -> Configuration Properties -> General -> Set Target Extension -> .mexw64;

6) Project -> Properties -> Configuration Properties -> General -> Configuration Type -> Dynamic Library (.dll);

7) Project -> Properties -> Configuration Properties -> General -> Use of MFC -> Use MFC in a Shared DLL;

8) Project -> Properties -> VC++ Directories -> Include Directories -> Add: C:\Program Files\MATLAB\R2015b\extern\include;

9) Project -> Properties -> Configuration properties -> Linker -> General -> Additional Library Directories -> Add: C:\Program Files\MATLAB\R2015b\extern\lib\win64\microsoft;

10) Project -> Properties -> Configuration properties -> Linker -> Input -> Additional Dependencies -> Add: libmx.lib; libmex.lib; libmat.lib;

11) Project -> Properties -> Configuration properties -> Linker -> Command Line -> Additional Options -> Add: /export:mexFunction

12) After the compilation, the mex file projectTitle.mexw64 will be available at …\projectRootDirectory\x64\Release; remember to add this directory in the Matlab script file; after that, you can call the C/C++ mex routine as a function whose name is the project name; remember to terminate the Matlab script with “clear mex” so that you can newly compile the project after any modification without having Matlab keeping the .mexw64 file busy.

Following this process, there is the possibility to receive the following error message

error MSB8031: Building an MFC project for a non-Unicode character set is deprecated. You must change the project property to Unicode or download an additional library. See Microsoft Support page for more information.

In this case, do the following:
13) Project -> Properties -> Configuration Properties -> General -> Character Set -> Use Unicode Character Set.

We have tested the procedure also for Matlab 2016b. We expect that it will work also for Visual Studio 2010 and Visual Studio 2012 and for other Matlab versions.

 

Leave a Reply

Your email address will not be published. Required fields are marked *