MATLAB Answers

Problem in specifying dependent library files by using MEX switches

7 ビュー (過去 30 日間)
AP 2013 年 2 月 13 日
回答済み: Yasuhiro Takagi 2020 年 5 月 24 日
I am trying to find the instructions for specifying the dependent library files as well as the path for compiling a c++ MEX file. Unfortunately, I wasn't successful and I couldn't get it to work. I don't know how to use:
Could someone please instruct me how to use these switches in Windows for the following case?
/LIBPATH:"C:\Program Files (x86)\lib\" / l64.lib cr.lib al.lib

回答 (4 件)

Kaustubha Govind
Kaustubha Govind 2013 年 2 月 13 日
You should just need to add them on to the "mex" command. Probably something like:
>> mex myfile.c -L"C:\Program Files (x86)\lib\" -l l64.lib -l cr.lib -l al.lib
  3 件のコメント
AP 2013 年 2 月 13 日
Thanks James. Your comment 100% makes sense to me. However, I get the following error:
C:\PROGRA~1\MATLAB\R2012B\BIN\MEX.PL: Error: 'C:\Program' not found.


Jan 2013 年 2 月 13 日
編集済み: Jan 2013 年 2 月 13 日
I had a similar problem with a space in the CFLAGS for Linux: Too add 'CFLAGS="\$CFLAGS -std=c99"' Matlab needs:
mex('CFLAGS="\$CFLAGS', '-std=c99"', ...)
The MEX command is too smart for parsing the non-functional form, so try this:
mex('myfile.c', '-L"C:\Program', 'Files', '(x86)\lib\"', '-l l64.lib', ...
'-l cr.lib', '-l al.lib')
This looks as strange as it is. Perhaps the spaces after "-l" are a problem also. I think they should be omitted.
I'm convinced, that MEX has been grown beyond a fair level of usability: Under Windows mex -setup creates a .bat file, which is not called as batch file, but parsed and evaluated in a perl script. Actually starting a compiler is trivial and a handmade M-function would be cleaner and more stable.
  2 件のコメント
Kaustubha Govind
Kaustubha Govind 2013 年 2 月 14 日
What about:
mex('myMEX.cpp','-I"C:\Program','Files','(x86)\FLRecon\include\"','-L"C:\Program Files (x86)\FLRecon\lib"','-l lp64.lib','-l cr.lib','-l al.lib')
(I'm wondering if maybe the -L option knows how to deal with the double-quote)


Manex Aguirrezabalaga
Manex Aguirrezabalaga 2019 年 9 月 30 日
I'm experiencing the exact same problem.
Matlab R2019B, Visual Studio 2015.
cl : Command line warning D9021 : no action performed
cl : Command line warning D9024 : unrecognized source file type 'Files\MATLAB\R2019b\extern\include -IC:\Program', object file assumed
Incidentally, it has relationship with "Program Files" being part of the MATLAB source folder.
Any workaround after 6 years?

Yasuhiro Takagi
Yasuhiro Takagi 2020 年 5 月 24 日
put -I, -L option in path string
mex '-IC:\Program Files\MATLAB\...' '-LC:\Program Files\MATLAB' -lscanuti hoge.cpp
If you get that by a command, like this.
mex_command = ['mex ''-I' matlabroot '\toolbox\vnt\vntblks\include\candatatype''']
It works with 2015a.

Community Treasure Hunt

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

Start Hunting!

Translated by