MATLAB Coder and MEX-file generation problem on Linux
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Athanasios Karapatis
el 18 de Nov. de 2014
Comentada: Mirko Fiacchini
el 24 de Mzo. de 2016
I am using Matlab R2014b on linux with gcc-4.7.
I tried to automatically generate a MEX file for a matlab code function with MATLAB coder. However I was getting a Build error and the Target Build Log was giving linking errors
_coder_WaveletFIR_idealFilter_mex.o: In function `mexFunction':
_coder_WaveletFIR_idealFilter_mex.c:(.text+0x30): undefined reference to `mexAtExit'
_coder_WaveletFIR_idealFilter_mex.c:(.text+0x57): undefined reference to `mxCalloc'
_coder_WaveletFIR_idealFilter_mex.c:(.text+0x124): undefined reference to `mxFree'
_coder_WaveletFIR_idealFilter_info.o: In function `b_emlrt_marshallOut':
_coder_WaveletFIR_idealFilter_info.c:(.text+0x5d): undefined reference to `mxGetData'
and the MEX was not generated. After some digging in the folders created I changed the following line in the makefile (i.e. WaveletFIR_idealFilter_mex.mk ) generated from Matlab-Coder
From:
$(TARGET): $(OBJLIST) $(MAKEFILE)
$(LD) $(EXPORTOPT) $(LINK_FLAGS) $(OBJLIST) $(SYS_LIBS)
To:
$(TARGET): $(OBJLIST) $(MAKEFILE)
$(LD) $(EXPORTOPT) $(OBJLIST) $(LINK_FLAGS) $(SYS_LIBS)
What I did is change the position of the $(LINK_FLAGS) and that worked.
And then I run manually the make wrapper(i.e. WaveletFIR_idealFilter_mex.sh ) that was available via command line. The MEX was correctly generated and I managed to use it. However the automated process in Matlab is still not working. This is because it is always re-writing the make file.
Is there a way I can solve it rather than doing it manually?
2 comentarios
Ryan Livingston
el 18 de Nov. de 2014
Editada: Ryan Livingston
el 18 de Nov. de 2014
Curious, I just tried a simple example using R2014b with GCC 4.7 and the Makefile used the pattern you showed but there was no error. Does this happen with trivial MATLAB code?
What Linux distro are you using? I tried on Debian Wheezy.
Are there any suspicious directory or file names either with spaces or special characters (e.g. $, %, &, etc) involved?
In theory, you could use something like sed to automatically make the change to the Makefile. In a MATLAB script:
!sed 's/$(LINK_FLAGS) $(OBJLIST)/$(OBJLIST) $(LINK_FLAGS)/g' -i codegen/mex/foo/foo_mex.mk
should do it if you update the path to the Makefile as appropriate. It would be better to understand the issue though.
Athanasios Karapatis
el 19 de Nov. de 2014
Editada: Athanasios Karapatis
el 19 de Nov. de 2014
Respuesta aceptada
Ryan Livingston
el 19 de Nov. de 2014
Editada: Ryan Livingston
el 24 de Nov. de 2014
EDIT: If you hit this issue and have a MathWorks account you can now refer to:
for a patch rather than needing to manually apply it. Otherwise, see below for the manual steps.
Thanks for the clarification, Athanasios. The GCC shipped with Ubuntu is slightly modified from the "vanilla" GCC. One consequence of this is that the Ubuntu GCC is slightly more sensitive to argument order.
The Makefile you are seeing is from a template inside the MATLAB installation. If you change this template in the same way you changed the generated Makefile, then the changes should always be applied.
The file to edit is:
MATLABROOT/toolbox/coder/coder/mex/c/mex_unix.mk
where MATLABROOT is the output of the command matlabroot in MATLAB.
To be explicit, you can make the change you suggested to swap $(LINK_FLAGS) and $(OBJLIST) so:
$(TARGET): $(OBJLIST) $(MAKEFILE)
$(LD) $(EXPORTOPT) $(LINK_FLAGS) $(OBJLIST) $(SYS_LIBS)
becomes:
$(TARGET): $(OBJLIST) $(MAKEFILE)
$(LD) $(EXPORTOPT) $(OBJLIST) $(LINK_FLAGS) $(SYS_LIBS)
3 comentarios
Ryan Livingston
el 19 de Nov. de 2014
Great to hear! We'll look into resolving this permanently for future releases of MATLAB Coder.
Más respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Coder en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!