MATLAB Coder and MEX-file generation problem on Linux
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Ryan Livingston
2014-11-18
编辑:Ryan Livingston
2014-11-18
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.
采纳的回答
Ryan Livingston
2014-11-19
编辑:Ryan Livingston
2014-11-24
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 个评论
Ryan Livingston
2014-11-19
Great to hear! We'll look into resolving this permanently for future releases of MATLAB Coder.
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!