Damien Marlier
Damien Marlier

Reputation: 446

Build mex file from Octave CLI

I am trying to build a mex file from octave but i am struggling with the spaces contained in the path. I tried the following command:

mex 'tsne_p.o' 'nvmatrix.o' 'nvmatrix_kernel.o' -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64" -lcuda -lcudart -lcufft -lcublas -I. -Wl,-rpath,"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64"

Unfortunately, the path is being splitted into multiple parts. Here is the log:

g++: error: Files/NVIDIA: No such file or directory
g++: error: GPU: No such file or directory
g++: error: Computing: No such file or directory
g++: error: Toolkit/CUDA/v8.0/lib/x64: No such file or directory
g++: error: unrecognized command line option '-Wl'
warning: mkoctfile exited with failure status
warning: called from
    mkoctfile at line 171 column 5
    mex at line 29 column 18
error: 'rpath' undefined near line 1 column 169

I tried replacing " by ' but it didn't change anything.

I eventually tried to call directly the .exe called by mex.m (using the windows command line). I tried with single quote, double backslash etc... but still get the same errors.

"C:\Octave\Octave-4.0.0\bin\mkoctfile-4.0.0.exe" "--mex" "tsne_p.o" "nvmatrix.o" "nvmatrix_kernel.o" -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64" -lcuda -lcudart -lcufft -lcublas -I. -Wl,-rpath,"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64"

g++: error: Files\NVIDIA: No such file or directory
g++: error: GPU: No such file or directory
g++: error: Computing: No such file or directory
g++: error: Toolkit\CUDA\v8.0\lib\x64: No such file or directory
g++: error: Files\NVIDIA: No such file or directory
g++: error: GPU: No such file or directory
g++: error: Computing: No such file or directory
g++: error: Toolkit\CUDA\v8.0\lib\x64: No such file or directory

Upvotes: 0

Views: 479

Answers (1)

carandraug
carandraug

Reputation: 13081

You can see it for yourself what is happening by checking what arguments you are actually passing to mex (remember that mex is just like any other Octave function, type which mex to find where you can see its source):

octave> function show_args (varargin), disp (varargin); endfunction
octave> show_args 'tsne_p.o' 'nvmatrix.o' 'nvmatrix_kernel.o' -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64"

{
  [1,1] = tsne_p.o
  [1,2] = nvmatrix.o
  [1,3] = nvmatrix_kernel.o
  [1,4] = -LC:Program FilesNVIDIA GPU Computing ToolkitCUDA
                                                           8.0libd
}

You can see that the problem is that you are not passing the path correctly, there is no file separators. Th reason is that you are using double quotes on that path string where the backslash is used to enter escape sequences. Of special interest is \v which is a vertical tab which is why 8.0libd is showing on the next line:

  [1,4] = -LC:Program FilesNVIDIA GPU Computing ToolkitCUDA
                                                           8.0libd

You can solve this by either using single quotes (which don't support escape sequences):

octave> show_args -L'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64'

{
  [1,1] = -LC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64
}

or escaping the backslashes:

octave> show_args -L"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\lib\\x64"

{
  [1,1] = -LC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64
}

I am not a Windows user and so I'm not sure of the following, but it's common for Unix programs to support Unix file separators even on Windows systems, where the file separator does not start an escape sequence:

octave> show_args -L"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/x64"

{
  [1,1] = -LC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/x64
}

Upvotes: 2

Related Questions