Correct syntax for building MEX files in 2014a using trailing backslash \ in file path names

1 view (last 30 days)
I mex my C file as follows:
>>  mex -output test -DBASE_PATH_NAME="T:\\directory\\" test.c
The file is mexed successfully in MATLAB R2013b. However, it fails in MATLAB R2014a with the following error:
Error using mex
test.c
T:\directory\test.c(9) : error C2001: newline in constant
T:\directory\test.c(11) : error C2143: syntax error : missing ';' before 'type'

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Mar 2014
As of R2014a, MATLAB supports single quotes (') to override a default compiler switch. For example,
 
>> mex -output test -DBASE_PATH_NAME='c:\\foo\\' test.c
 
If you use double quotes (") instead of single quotes, the compiler interprets \" as an escape sequence. If you want to add a trailing backslash character to a path name, you must add the backslash escape character:
 
For example, replace:
>> mex -output test -DBASE_PATH_NAME="c:\\foo\\" test.c
 
with:
>> mex -output test -DBASE_PATH_NAME="c:\\foo\\\\" test.c
As this adds unnecessary characters it is best practice to adopt the new format of using single quotes in specifying arguments passed to the compiler.

More Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!