Question about building MEX file

1 view (last 30 days)
Hello,
I'm learning others' work on building MEX file and find a command like the following:
mex [certain source files] rfsub.o -o mexClassRF_train -lm -DMATLAB -O -v
I have several questions about this command and couldn't find answers from google...
1) rfsub.o is certain pre-compiled object file that has been provided, I can't figure out the usage of this 'rfsub.o' in the command line. (My guess is rfsub.o is actually the object file compiled from the source files, namely the output of this mex command, the author provided the pre-compiled file just for our convenience. If my guess is right then the 'rfsub.o' in the command line is to define the name of output?)
2) What is '-lm' for? I check the document, there's an option '-lname' which is for linking with object library, so I guess -lm means linking with a library named 'm'? However I couldn't find any file provided with name 'm', seems my guess is wrong...
3) What is -DMATLAB for? Again the document says '-D' is equivalent to '#define name directive' in C/C++, I still can't get it, in C/C++ when you define something you have #define name value, here you only have #define name, what's that mean then?
Thank you in advance!

Accepted Answer

Walter Roberson
Walter Roberson on 9 Sep 2012
In that context, rfsub.o means to link in the already-compiled source for rfsub
The output in that command is given by the -o ("output") flag, as mexClassRF_train
-lm does indeed link in a library named "m". That is the common name used for the C math library, and would probably be in the directories provided with the compilers.
-DMATLAB does define the symbol MATLAB. In C and C++ it is not necessary to provide a value. As the Microsoft documentation says,
A #define without a token-string removes occurrences of identifier from the source file. The identifier remains defined and can be tested using the #if defined and #ifdef directives.
  1 Comment
Kaustubha Govind
Kaustubha Govind on 10 Sep 2012
You might want to search for "libm" instead of just "m".

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!