MATLAB crashes when absolute path is used in a .mex file

I have a .mex file which writes information to a file and accepts as one of its arguments the file name/path. When I pass a relative path, i.e.
foo(__,'../../SomeDirectory/filename.ext')
everything is fine. I have tried very convoluted relative paths and it works every time. When I decide to pass an absolute path, like
foo(__,'C:/SomeDirectory/SomeDirectory2/SomeDirectory3/filename.ext')
MATLAB closes.

3 commentaires

OCDER
OCDER le 25 Juin 2018
Modifié(e) : OCDER le 25 Juin 2018
Can you provide the mex source code?
dpb
dpb le 25 Juin 2018
Any chance the absolute path contains embedded blanks and isn't being double-quoted or somesuch?
As OCDER says, a minimal example code that illustrates the problem would be most helpful; debugging from symptom only is tough.
Agreed! Will do it in future. Thank you!

Connectez-vous pour commenter.

 Réponse acceptée

I found the problem. Deep in one of the support files the function which writes information to file had the directory and filename as separate inputs, like so:
foo_write_to_file(double info_to_write, char *directory, char *filename)
At top level, only the variable filename exists
foo_top_level(double info_to_write, char *filename)
and the directory was hard-coded as "." i.e.
foo_write_to_file(info_to_write, ".", filename)
When I called the function with a relative path it started from the current directory, "." and went the appropriate levels up, etc. When I pass absolute path name, it was trying to go to "./C:/...".

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by