简体   繁体   English

检查是否使用MATLAB mex进行编译

[英]Check if compiling with MATLAB mex

I want to make a cross-platform function that has extra functionalities if compiled under MATLAB. 如果要在MATLAB下编译,我想制作一个具有额外功能的跨平台功能。 Is there a define that can give me that information? 有没有可以给我这些信息的定义?

In other words, I'm implementing it as follows: 换句话说,我将其实现如下:

void f(void) {
    if (x) {
        (...)
    }
#ifdef MATLAB
    do_other_stuff();
#endif
}

and I need to have something replacing 我需要更换一些东西

#ifdef MATLAB

to verify that it is being compiled under matlab as a MEX function. 验证它是否已在matlab下作为MEX函数进行编译。

My '>> mex -v' outputs this: 我的'>> mex -v'输出如下:

'>> mex -v
-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)    
   FILE = /home/bmmo/.matlab/R2009b/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /usr/matlab2009b
->    CC                    = gcc
->    CC flags:
         CFLAGS             = -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread
         CDEBUGFLAGS        = -g
         COPTIMFLAGS        = -O -DNDEBUG
         CLIBS              = -Wl,-rpath-link,/usr/matlab2009b/bin/glnxa64 -L/usr/matlab2009b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
         arguments          =  -DMX_COMPAT_32
->    CXX                   = g++
->    CXX flags:
         CXXFLAGS           = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
         CXXDEBUGFLAGS      = -g
         CXXOPTIMFLAGS      = -O -DNDEBUG
         CXXLIBS            = -Wl,-rpath-link,/usr/matlab2009b/bin/glnxa64 -L/usr/matlab2009b/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments          =  -DMX_COMPAT_32
->    FC                    = g95
->    FC flags:
         FFLAGS             = -fexceptions -fPIC -fno-omit-frame-pointer
         FDEBUGFLAGS        = -g
         FOPTIMFLAGS        = -O
         FLIBS              = -Wl,-rpath-link,/usr/matlab2009b/bin/glnxa64 -L/usr/matlab2009b/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments          =  -DMX_COMPAT_32
->    LD                    = gcc
->    Link flags:
         LDFLAGS            = -pthread -shared -Wl,--version-script,/usr/matlab2009b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
         LDDEBUGFLAGS       = -g
         LDOPTIMFLAGS       = -O
         LDEXTENSION        = .mexa64
         arguments          = 
->    LDCXX                 = 
->    Link flags:
         LDCXXFLAGS         = 
         LDCXXDEBUGFLAGS    = 
         LDCXXOPTIMFLAGS    = 
         LDCXXEXTENSION     = 
         arguments          = 
----------------------------------------------------------------

Thanks in advance. 提前致谢。

Try running 尝试跑步

>> mex -v

in your Matlab and inspect the COMPFLAGS it lists. 在您的Matlab中,检查列出的COMPFLAGS

On my machine I see /DMATLAB_MEX_FILE that is a const MATLAB_MEX_FILE is being defined. 在我的机器上,我看到/DMATLAB_MEX_FILE被定义为常量MATLAB_MEX_FILE I guess this is the case for other platforms, but its worth checking in advance. 我想其他平台也是如此,但值得提前检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM