craigim
craigim

Reputation: 3914

Mex cannot find a file, but "which" can

I am trying to compile a C++ function (found here). I downloaded the requisite packages, installed Microsoft Windows SDK 7.1, linked it to MATLAB using mex -setup, and then unzipped the function packages into my MATLAB path.

When I run the command:

mex -output Faddeeva_w -O Faddeeva_w_mex.cc Faddeeva.cc

I get the error message:

C:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: 'Faddeeva_w_mex.cc' not found. 

But if I type which Faddeeva_w_mex.cc I get:

C:\Users\craigim\Documents\Code\Matlab\Faddeeva-MATLAB\Faddeeva_w_mex.cc

So MATLAB and the which command have no problems finding the file, but mex is lost. This is my very first attempt at compiling something with mex, so I'm really not sure where to start here. Does mex have a different path variable that I have to set?

I'm using MATLAB 2013a on a Windows 7 64bit machine with the version of SDK 7.1 that was linked from the MATLAB List of supported compilers.

Upvotes: 1

Views: 1421

Answers (2)

Engineero
Engineero

Reputation: 12938

Try putting addpath('C:\Users\craigim\Documents\Code\Matlab\Faddeeva-MATLAB\'); in your m-file. The path that MATLAB uses seems to be internal and independent of whatever your OS is using.

Documentation on addpath here.

And a similar discussion here.

You may also have to set your PATH environment variable to the string returned by the command fullfile(matlabroot,'bin',computer('arch')) in MATLAB. Here are some instructions on setting environment variables for Windows and Mac or Linux

There is also a pretty good overview of building mex-files here although I get the impression that the basics are not going to answer your question.

Upvotes: 1

Amro
Amro

Reputation: 124563

Either cd into the directory containing the files (assuming they both in the same place), or specify full/relative path to the C++ files when invoking mex function

Upvotes: 3

Related Questions