matlab编写的mex文件:如何重新编译

时间:2015-02-11 14:24:27

标签: c matlab mex matlab-coder

我最近将一些我的Matlab代码转换为C并且它可以工作。但是,我想对这些mex文件进行一些更改并重新编译。

到目前为止,我只使用过简单的mex项目:通常包含两个这样的文件:

  Matlab_mex_Testing.m <--- I call mex function from here.
  mexcallingmatlab.c 

然后我可以使用:

进行编译
  mex -g -ldl CFLAGS="\$CFLAGS -std=c99" -largeArrayDims mexcallingmatlab.c

但是,转换后的项目有多个* .c,* .o文件,当我尝试只编译.... _ mex.c时,我收到以下错误:

  ConstructSystemMatrix_2Translate_mex.c:24:1: warning: excess elements in struct initializer [enabled by default]
   emlrtContext emlrtContextGlobal = { true, false, EMLRT_VERSION_INFO, NULL, "ConstructSystemMatrix_2Translate", NULL, false, {2045744189U,2170104910U,2743257031U,4284093946U}, 0, false, 1, false };
   ^
  ConstructSystemMatrix_2Translate_mex.c:24:1: warning: (near initialization for ‘emlrtContextGlobal’) [enabled by default]
  ConstructSystemMatrix_2Translate_mex.c:24:1: warning: excess elements in struct initializer [enabled by default]
  ConstructSystemMatrix_2Translate_mex.c:24:1: warning: (near initialization for ‘emlrtContextGlobal’) [enabled by default]
  ConstructSystemMatrix_2Translate_mex.c:24:1: warning: excess elements in struct initializer [enabled by default]
  ConstructSystemMatrix_2Translate_mex.c:24:1: warning: (near initialization for ‘emlrtContextGlobal’) [enabled by default]
  ConstructSystemMatrix_2Translate_mex.c: In function ‘mexFunction’:
  ConstructSystemMatrix_2Translate_mex.c:57:3: warning: implicit declaration of function ‘emlrtClearAllocCount’ [-Wimplicit-function-declaration]
     emlrtClearAllocCount(&emlrtContextGlobal, 0, 0, NULL);
     ^
  ConstructSystemMatrix_2Translate_mex.o: In function `ConstructSystemMatrix_2Translate_mexFunction':
  /home/dkumar/Desktop/codegen/mex/ConstructSystemMatrix_2Translate/ConstructSystemMatrix_2Translate_mex.c:37: undefined reference to `ConstructSystemMatrix_2Translate_initialize'
  /home/dkumar/Desktop/codegen/mex/ConstructSystemMatrix_2Translate/ConstructSystemMatrix_2Translate_mex.c:39: undefined reference to `ConstructSystemMatrix_2Translate_api'
  /home/dkumar/Desktop/codegen/mex/ConstructSystemMatrix_2Translate/ConstructSystemMatrix_2Translate_mex.c:41: undefined reference to `ConstructSystemMatrix_2Translate_terminate'
  ConstructSystemMatrix_2Translate_mex.o: In function `ConstructSystemMatrix_2Translate_atexit_wrapper':
  /home/dkumar/Desktop/codegen/mex/ConstructSystemMatrix_2Translate/ConstructSystemMatrix_2Translate_mex.c:50: undefined reference to `ConstructSystemMatrix_2Translate_atexit'
  ConstructSystemMatrix_2Translate_mex.o: In function `mexFunction':
  /home/dkumar/Desktop/codegen/mex/ConstructSystemMatrix_2Translate/ConstructSystemMatrix_2Translate_mex.c:57: undefined reference to `emlrtClearAllocCount'
  collect2: error: ld returned 1 exit status

      mex: link of ' "ConstructSystemMatrix_2Translate_mex.mexa64"' failed.

  mex -g -ldl CFLAGS="\$CFLAGS -std=c99" -largeArrayDims ConstructSystemMatrix_2Translate_mex.c: Signal 127

  ans =

     255

我可以看到正确包含各种头文件,例如“ConstructSystemMatrix_2Translate_initialize.h”等。

我还看到*.mki file有以下内容:

  # Make settings for ConstructSystemMatrix_2Translate
  CC=gcc
  CFLAGS=-ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread
  CLIBS=-Wl,-rpath-link,/usr/local/MATLAB/R2012a/bin/glnxa64 -L/usr/local/MATLAB/R2012a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
  COPTIMFLAGS=-O -DNDEBUG
  CDEBUGFLAGS=-g
  CXX=g++
  CXXFLAGS=-ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
  CXXLIBS=-Wl,-rpath-link,/usr/local/MATLAB/R2012a/bin/glnxa64 -L/usr/local/MATLAB/R2012a/bin/glnxa64 -lmx -lmex -lmat -lm
  CXXOPTIMFLAGS=-O -DNDEBUG
  CXXDEBUGFLAGS=-g
  LD=gcc
  LDFLAGS=-pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2012a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
  LDOPTIMFLAGS=-O
  LDDEBUGFLAGS=-g
  Arch=glnxa64
  OMPFLAGS=
  OMPLINKFLAGS=
  EMC_COMPILER=
  EMC_CONFIG=optim

我应该make some makefile out of this吗?如果是,有人可以指导我吗?

我正在运行Matlab R2014b(64位)

0 个答案:

没有答案