MATLAB Answers

mex file generated by Matlab-coder: how to recompile

3 views (last 30 days)
Dushyant
Dushyant on 11 Feb 2015
Hi,
I recently got some of my Matlab code converted to C and it works. However, I would like to make some changes to these mex file and recompile.
So far, my mex project so far used to be very simple: it consists of two files like this:
Matlab_mex_Testing.m <--- I call mex function from here.
mexcallingmatlab.c
then I can compile using:
mex -g -ldl CFLAGS="\$CFLAGS -std=c99" -largeArrayDims mexcallingmatlab.c
However, the converted project has multiple *.c, *.o files and when I tried to compile only the ...._mex.c, I get following error:
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
I cn see that various header files such as "ConstructSystemMatrix_2Translate_initialize.h" etc are properly included.
I also see that there is a *.mki file with following contents:
# 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
Am I supposed to make some makefile out of this? If yes, could someone guide me?
I am running Matlab R2014b (64 bits)

  0 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!