Compiling ‘LIBLINEAR MKL : A Fast Multiple Kernel Learning L1/L2-loss SVM solver in MATLAB’

Link to library: liblinear-mkl
The provided Makefile in matlab directory is outdated , I have updated the file and posting it below:

# This Makefile is used under Linux

MATLABDIR ?= /home/guo/MATLAB/R2015b
CXX ?= g++
#CXX = g++-3.3
CC ?= gcc

CFLAGS = -Wall -Wconversion -O3 -fPIC -I$(MATLABDIR)/extern/include -I..

MEX = $(MATLABDIR)/bin/mex
#MEX_OPTION = CC\#$(CXX) CXX\#$(CXX) CFLAGS\#"$(CFLAGS)" CXXFLAGS\#"$(CFLAGS)"
MEX_OPTION = CXX=$(CXX) CXXFLAGS="$(CFLAGS)"
# comment the following line if you use MATLAB on a 32-bit computer
MEX_OPTION += -largeArrayDims
MEX_EXT = $(shell $(MATLABDIR)/bin/mexext)

OCTAVEDIR ?= /usr/include/octave
OCTAVE_MEX = env CC=$(CXX) mkoctfile
OCTAVE_MEX_OPTION = --mex
OCTAVE_MEX_EXT = mex
OCTAVE_CFLAGS = -Wall -O3 -fPIC -I$(OCTAVEDIR) -I..

all:	matlab

matlab:	binary

octave:
@make MEX="$(OCTAVE_MEX)" MEX_OPTION="$(OCTAVE_MEX_OPTION)" \
MEX_EXT="$(OCTAVE_MEX_EXT)" CFLAGS="$(OCTAVE_CFLAGS)" \
binary

binary: train.$(MEX_EXT) predict.$(MEX_EXT) libsvmread.$(MEX_EXT) libsvmwrite.$(MEX_EXT)

train.$(MEX_EXT): train.c ../linear.h ../tron.o ../linear.o linear_model_matlab.o ../blas/blas.a
$(MEX) $(MEX_OPTION) train.c linear_model_matlab.c ../tron.o ../linear.o linear_model_matlab.o ../blas/blas.a

predict.$(MEX_EXT): predict.c ../linear.h ../tron.o ../linear.o linear_model_matlab.o ../blas/blas.a
$(MEX) $(MEX_OPTION) predict.c linear_model_matlab.c ../tron.o ../linear.o linear_model_matlab.o ../blas/blas.a

libsvmread.$(MEX_EXT):	libsvmread.c
$(MEX) $(MEX_OPTION) libsvmread.c

libsvmwrite.$(MEX_EXT):	libsvmwrite.c
$(MEX) $(MEX_OPTION) libsvmwrite.c

linear_model_matlab.o: linear_model_matlab.c ../linear.h
$(CXX) $(CFLAGS) -c linear_model_matlab.c

../linear.o:
cd ..; make linear.o

../tron.o:
cd ..; make tron.o

../blas/blas.a:
cd ../blas; make OPTFLAGS='$(CFLAGS)' CC='$(CC)';

clean:
cd ../blas;	make clean
rm -f *~ *.o *.mex* *.obj ../linear.o ../tron.o

Things to notice:

1) Updating the MATLABDIR to your installation directory for matlab
2) Change all the C++ style inline comments in c files to C style comment (/**/), I tried using the ‘-std=c99’ switch but make seems to ignore that , moreover, gcc might not need that at all. Strange.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s