MATLAB Coder and MEX-file generation problem on Linux
Show older comments
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 Comments
Ryan Livingston
on 18 Nov 2014
Edited: Ryan Livingston
on 18 Nov 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
on 19 Nov 2014
Edited: Athanasios Karapatis
on 19 Nov 2014
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!