Question about building MEX file

1 次查看(过去 30 天)
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!

采纳的回答

Walter Roberson
Walter Roberson 2012-9-9
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by