MATLAB: Am I unable to build the mexGPUExample.cu example in MATLAB R2014b on Linux

Parallel Computing Toolbox

I am following the Run MEX-Functions Containing CUDA Code example in MATLAB R2014b on Linux. But when I try to perform the actual compilation:
mex -v -largeArrayDims mexGPUExample.cu
The build fails with:
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /home/myuser/.matlab/R2014b/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /usr/local/MATLAB/R2014b
-> CC = gcc
-> CC flags:
CFLAGS = -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread
CDEBUGFLAGS = -g
COPTIMFLAGS = -O -DNDEBUG
CLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2014b/bin/glnxa64 -L/usr/local/MATLAB/R2014b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
arguments =
-> CXX = g++
-> CXX flags:
CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O -DNDEBUG
CXXLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2014b/bin/glnxa64 -L/usr/local/MATLAB/R2014b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments =
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2014b/bin/glnxa64 -L/usr/local/MATLAB/R2014b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments =
-> LD = g++
-> Link flags:
LDFLAGS = -v -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2014b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
-> g++ -c -I/usr/local/MATLAB/R2014b/extern/include -I/usr/local/MATLAB/R2014b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -O -DNDEBUG "mexGPUExample.cu"
g++: warning: mexGPUExample.cu: linker input file unused because linking not done
-> g++ -O -v -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2014b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -o "mexGPUExample.mexa64" mexGPUExample.o -Wl,-rpath-link,/usr/local/MATLAB/R2014b/bin/glnxa64 -L/usr/local/MATLAB/R2014b/bin/glnxa64 -lmx -lmex -lmat -lm
g++: error: mexGPUExample.o: No such file or directory

Best Answer

At the top of this build output we see the lines: 
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /home/myuser/.matlab/R2014b/mexopts.sh
This is not what we would expect to see when building for CUDA on MATLAB R2014b. mexopts.sh is related to building MEX files on MATLAB releases before release R2014a. If you still have a copy of mexopts.sh in your preferences directory or current working directory this still will be used however. (MATLAB may have copied it from a previous MATLAB installation if you had manually modified mexopts.sh).
To resolve the issue delete this custom mexopts.sh from your preferences directory.
 
Related Question