mex error for path names with spaces

9 Ansichten (letzte 30 Tage)
Marina Frants
Marina Frants am 23 Sep. 2021
Kommentiert: Walter Roberson am 27 Sep. 2021
I'm running Matlab R2016b (no, I can't upgrade it, that's what my employer is licensed for) on Windows, and trying to use mex to compile a c++ script I was given. I need to include MySQL in the compile, and I'm trying to do so as follows:
mex <my script> -I'C:\Program Files\MySQL\MySQL Server 8.0\include\' -L'C:\Program Files\MySQL\MySQL Server 8.0\lib' -lmysqlclient
I get the following error:
Building with 'MinGW64 Compiler (C++)'.
Error using mex
g++: error: Files\MATLAB\R2016b/extern/include -IC:\Program: Invalid argument
g++: error: Files\MATLAB\R2016b/simulink/include -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG
C:\Users\marina\ZooScanDatabase_scripts_GUI_access_09Jun2021_R2016b\mysql.cpp -o
C:\Users\marko\AppData\Local\Temp\mex_71592438356584_12624\mysql.obj : No such file or directory
g++: fatal error: no input files
compilation terminated.
It looks like mex is having problems with the spaces in the path names I'm giving to -I and -L. I tried different combinations of single and double qotes, as well as no quotes at all, but nothing works. Is there a way to get around this?
  1 Kommentar
Jan
Jan am 23 Sep. 2021
"I tried different combinations of single and double quotes"
It is useful to post, what you have tried. Then the readers do not have to post this again.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Marina Frants
Marina Frants am 24 Sep. 2021
Well, I found a very kludgey work-around. I'm not sure why it works when single quotes don't, but it's better than nothing I guess.
Basically, I did cd to the include directory withing matlab, and set includelib=pwd. Then did the same in the link directory, with linklib=pwd.
Then I did the mex command as follows:
mex('<myfile>', ['-I' includelib], ['-L' linklib], '-lmysqlclient')
Of course, now I'm getting a ton of compiler errors, but that's an issue for a different question...
  3 Kommentare
Marina Frants
Marina Frants am 27 Sep. 2021
Jan,
I agree that is should be exactly the same, but it doesn't work:
mex('mysql.cpp',...
'-IC:\Program Files\MySQL\MySQL Server 8.0\include\',...
'-LC:\Program Files\MySQL\MySQL Server 8.0\lib\',...
'-llibmysql')
Building with 'MinGW64 Compiler (C++)'.
Error using mex
g++: error: Files\MATLAB\R2016b/extern/include -IC:\Program: Invalid argument
g++: error: Files\MATLAB\R2016b/simulink/include -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG
C:\Users\marina\ZooScanDatabase_scripts_GUI_access_09Jun2021_R2016b\mysql.cpp -o
C:\Users\marko\AppData\Local\Temp\mex_892763431102152_15956\mysql.obj : No such file or directory
g++: fatal error: no input files
compilation terminated.
Only the workaround with pwd works.
Walter Roberson
Walter Roberson am 27 Sep. 2021
mex('mysql.cpp',...
'-I"C:\Program Files\MySQL\MySQL Server 8.0\include\"',...
'-L"C:\Program Files\MySQL\MySQL Server 8.0\lib\"',...
'-llibmysql')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Jan
Jan am 23 Sep. 2021
Try this:
mex('<my script>', '-I"C:\Program Files\MySQL\MySQL Server 8.0\include\"', ...
'-L"C:\Program Files\MySQL\MySQL Server 8.0\lib"', '-lmysqlclient')
  1 Kommentar
Marina Frants
Marina Frants am 23 Sep. 2021
Hi, Jan.
I tried it just now, and got the same error.
I've also tried:
mex <my script> -I'"C:\Program Files\MySQL\MySQL Server 8.0\include\" ' -L'"C:\Program Files\MySQL\MySQL Server 8.0\lib"' -lmysqlclient
and:
mex <my script> -I"C:\Program Files\MySQL\MySQL Server 8.0\include\"-L"C:\Program Files\MySQL\MySQL Server 8.0\lib" -lmysqlclient
No luck with any of them.

Melden Sie sich an, um zu kommentieren.


Steven Lord
Steven Lord am 23 Sep. 2021
Wrap all the text inputs that can contain spaces in single quotes.
disp 'Hello world!' % Equivalent of disp('Hello world!')
Hello world!
fprintf '%s \t%s\n' 'abracadabra' 'hocus pocus' % fprintf('%s \t%s\n', 'abracadabra', 'hocus pocus')
abracadabra hocus pocus

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by