Problems compiling CUDA with MEX in Matlab2014a

Hi,

I tried to compile a CUDA program using MEX and can’t get it to work.
I installed the newest CUDA toolbox (6.5) and driver (340.62) and the samples work correctly, so I guess it is correctly installed.

I also installed MS Visual Studio 2012 Professional and Matlab 2014a.

I followed the exact description in the Matlab Help in “GPU Computing -> Examples and How To -> Run MEX-Functions Containing CUDA Code”.
My CUDA file ends with .cu (so I am trying to compile Matlab’s standard example mexGPUExample.cu, but I get the same error with other .cu files), the mex_CUDA_win64.xml is in the same folder, the environment variable MW_NVCC_PATH is set correctly in the user variables and just to be sure I also called “setenv('MW_NVCC_PATH,…)” in Matlab.

If I try to compile a CUDA example with

mex -largeArrayDims mexGPUExample.cu

I get the following error:

cl : Command line warning D9024 : unrecognized source file type 'mexGPUExample.cu', object file assumed 
cl : Command line warning D9027 : source file 'mexGPUExample.cu' ignored 
cl : Command line warning D9021 : no action performed 
 
  D:\PROGRAMS\MATLAB~1\BIN\MEX.PL: Error: Compile of 'mexGPUExample.cu' failed. 
 
Unable to complete successfully.

I also tried to set the compiler correctly using

mex -setup

and chose the MS Visual Studio Compiler.

The code itself works because I tested it on other systems.

I have no idea what I am doing wrong.
Any help is appreciated.

This works:

http://www.orangeowlsolutions.com/archives/498

So, I tried this, but got the following compile error.
I usually do not use Visual Studio, so I am not sure how to correct these.
But shouldn’t the CUDA programs compile from within Matlab? I thought Matlab only makes use of the VS compiler. This seems to be a very complicated solution.

1>------ Build started: Project: cudaTest, Configuration: Debug x64 ------
1>  Compiling CUDA source file SquareArrayCUDA.cu...
1>  
1>  F:\ICG\local\Testprograms\Matlab\CUDA\cudaTest\cudaTest>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64"  -ID:\programs\Matlab2014b\extern\include -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include"  -G   --keep-dir x64\Debug -maxrregcount=0  --machine 64 --compile -cudart static  -g   -DWIN32 -D_WINDOWS -D_DEBUG -D_USRDLL -D_WINDLL -D_UNICODE -DUNICODE -D_AFXDLL -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o x64\Debug\SquareArrayCUDA.cu.obj "F:\ICG\local\Testprograms\Matlab\CUDA\cudaTest\cudaTest\SquareArrayCUDA.cu" 
1>  SquareArrayCUDA.cu
1>  stdafx.cpp
1>  SquareArray.cpp
1>SquareArray.cpp(43): warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
1>  cudaTest.cpp
1>  Generating Code...
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(1137,5): warning MSB8012: TargetPath(F:\ICG\local\Testprograms\Matlab\CUDA\cudaTest\x64\Debug\cudaTest.dll) does not match the Linker's OutputFile property value (F:\ICG\local\Testprograms\Matlab\CUDA\cudaTest\x64\Debug\cudaTest.mexw64). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(1138,5): warning MSB8012: TargetExt(.dll) does not match the Linker's OutputFile property value (.mexw64). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1>mfcs110ud.lib(dllmodul.obj) : error LNK2005: DllMain already defined in MSVCRTD.lib(dllmain.obj)
1>.\cudaTest.def(8): warning LNK4017: LIBRARY statement not supported for the target platform; ignored
1>     Creating library F:\ICG\local\Testprograms\Matlab\CUDA\cudaTest\x64\Debug\cudaTest.lib and object F:\ICG\local\Testprograms\Matlab\CUDA\cudaTest\x64\Debug\cudaTest.exp
1>F:\ICG\local\Testprograms\Matlab\CUDA\cudaTest\x64\Debug\cudaTest.mexw64 : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========