Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Linux Matlab R2010b Mex and MKL 10.3

kramulous
Beginner
511 Views
Hi,
I'm having issues linking where I haven't had them before.
I use the makefile:
[bash]#!/bin/bash
# This Makefile is used under Linux for mex file generation

# Cluster = Matlab_2010b
#MATLABDIR ?= /pkg/matlab_x86_64/R2010b

# Firstname Surname workstation
MATLABDIR ?= /home/username/Software/R2010b
# for Mac
# MATLABDIR ?= /opt/local/matlab

INTEL = /opt/intel/composerxe-2011.0.084
MKLROOT = $(INTEL)/mkl/lib/intel64

CXX = icpc
# -Wall -Wconversion and -fPIC are required for the mex
CFLAGS = -Wall -Wconversion -fPIC -O3 -DMKL_ILP64 -I$(MATLABDIR)/extern/include -limf -L$(MKLROOT) -Wl,--start-group -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -Wl,--end-group -lpthread

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


all:	matlab

matlab:	binary

binary: marg_exact_approx.$(MEX_EXT) 

marg_exact_approx.$(MEX_EXT):     
	$(MEX) $(MEX_OPTION) marg_exact_approx.cpp 

clean:
	rm -f *~ *.o *.mex* *.obj
[/bash]

But I'm getting undefined reference:

[username@host Mex]$ make
/home/username/Software/R2010b/bin/mex CXX#icpc CXXFLAGS#"-Wall -Wconversion -fPIC -O3 -DMKL_ILP64 -I/home/username/Software/R2010b/extern/include -limf -L/opt/intel/composerxe-2011.0.084/mkl/lib/intel64 -Wl,--start-group -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -Wl,--end-group -lpthread" -largeArrayDims marg_exact_approx.cpp
marg_exact_approx.o: In function `mexFunction':
marg_exact_approx.cpp:(.text+0x184): undefined reference to `vslNewStream'
marg_exact_approx.cpp:(.text+0x253): undefined reference to `vdRngGamma'
marg_exact_approx.cpp:(.text+0x280): undefined reference to `vdRngGamma'
marg_exact_approx.cpp:(.text+0x2bb): undefined reference to `vdRngGamma'
marg_exact_approx.cpp:(.text+0x2e8): undefined reference to `vdRngGamma'
marg_exact_approx.cpp:(.text+0x360): undefined reference to `vdRngGamma'
marg_exact_approx.o:marg_exact_approx.cpp:(.text+0x398): more undefined references to `vdRngGamma' follow
marg_exact_approx.o: In function `mexFunction':
marg_exact_approx.cpp:(.text+0x3b7): undefined reference to `vslDeleteStream'
mex: link of ' "marg_exact_approx.mexa64"' failed.
make: *** [marg_exact_approx./home/username/Software/R2010b/bin/mexext] Error 1

When I name mangle the libraries I've specified, the functions are there.

nm libmkl_intel_ilp64.so | grep vdRngGamma
000000000039abd0 T vdRngGamma
0 Kudos
4 Replies
Gennady_F_Intel
Moderator
511 Views
there is some mismatching:
CFLAGS=-Wall-Wconversion-fPIC-O3-DMKL_ILP64-I$(MATLABDIR)/extern/include-limf-L$(MKLROOT)-Wl,--start-group-lmkl_intel_lp64-lmkl_sequential-lmkl_core-Wl,--end-group-lpthread
0 Kudos
mecej4
Honored Contributor III
511 Views
Before line 20, where you use CXXFLAGS, you need a line where that symbol is set to the list of icpc options desired.

I do not know how the Mex script of your version of Matlab is put together, but the compiler command should come out with CXXFLAGS replaced by its value, rather than literally. That would require your using $(CXXFLAGS) on line-20.

If the Mex script has become corrupted, you need to fix it or replace it with the original.
0 Kudos
kramulous
Beginner
511 Views
Hi Gennady,
When I posted the Makefile, I played around a little more and accidently posted the mismatch.
0 Kudos
kramulous
Beginner
511 Views
Hi all,
I've got it working now and posting back a solution to complete the thread. mecej4's post above forced me to be a little more critical of my makefile.
As a result, I completely removed Matlab's /bin/mex binary due to insufficient arguments to configure libraries, etc.
[bash]#!/bin/make

BINARY = marg_exact_approx
MEX_SUFFIX = mexa64

MATLAB = /home/username/Software/R2010b
INTEL = /opt/intel/composerxe-2011.0.084
MKLROOT = $(INTEL)/mkl/lib/intel64

CC = icpc
OPTS = -DMATLAB_MEX_FILE -DMKL_ILP64 -fPIC -fno-omit-frame-pointer -DMX_COMPAT_32 -O3 -xHost
SRC = marg_exact_approx.cpp
OBJS = $(SRC:.cpp=.o)


INC = -I$(MATLAB)/extern/include -I$(MATLAB)/simulink/include
LIBS = -shared -Wl,--version-script,$(MATLAB)/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined 
LIBS += -Wl,-rpath-link,$(MATLAB)/bin/glnxa64 -L$(MATLAB)/bin/glnxa64 -lmx -lmex -lmat -Wl,--start-group $(MKLROOT)/libmkl_intel_ilp64.a $(MKLROOT)/libmkl_sequential.a $(MKLROOT)/libmkl_core.a -Wl,--end-group -lpthread

.SUFFIXES: .cpp .o

.cpp.o:
	$(CC) $(OPTS) $(INC) -c $< -o $@

Go: $(OBJS)
	$(CC) $(OBJS) $(OPTS) -o $(BINARY).$(MEX_SUFFIX) $(LIBS)
	@echo Binary created!!

clean:
	set nonomatch; rm -f $(BINARY).$(MEX_SUFFIX) *.o
[/bash]
I also had to change mkl to being statically linked as there was a mismatch between Matlab libraries and as a result was getting (when executing the mex file within Matlab):

/home/username/Software/R2010b/bin/glnxa64/MATLAB: symbol lookup error: /opt/intel/composerxe-2011.0.084/mkl/lib/intel64/libmkl_vml_mc3.so: undefined symbol: mkl_serv_mkl_malloc


hooroo
0 Kudos
Reply