function compile() target = 'foo'; % mystr1 sets up environment variables for compiling. % my "mex" compiler is 64 bit, so there's a bunch of stuff % that specifies the architecture of the machine. % "nvcc" is cuda compiler mystr1 = '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x64 & nvcc -c -gencode=arch=compute_11,code=\"sm_11,compute_11\" --use-local-env --cl-version 2010 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" --machine 64 -Xcompiler "/EHsc /MDd " '; mycommand = ['!', mystr1, target, '.cu']; eval(mycommand); % now we compile the ".cpp" file and specify CUDA libraries mystr2 = '-L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\lib\x64" -lcudart'; mycommand = ['mex ', mystr2, ' ', target, '.cpp ', target, '.obj']; eval(mycommand);