Hi,
I am facing a link problem with mkl under linux (Ubuntu 12.04) recently. I am trying to make my code work but it always tell me that there are link errors. The make file is:
%%%%%%%%%%%%%%% Makefile %%%%%%%%%%%%%
CC=g++ -DMKL_ILP64 -m64
MKLPATH = /opt/intel/composer_xe_2013_sp1.0.080/mkl
CFLAGS=-c -Wall
LIBS = -L$(MKLPATH)/lib/intel64
LDFLAGS= $(MKLPATH)/lib/intel64/libmkl_intel_ilp64.a -Wl,--start-group $(MKLPATH)/lib/intel64/libmkl_core.a $(MKLPATH)/lib/intel64/libmkl_sequential.a -Wl,--end-group $(LIBS) -lpthread -lm
INCLUDES = -I$(MKLPATH)/include
SOURCES=main_gf.cpp gfgraph.cpp gfreader.cpp gfsmw.cpp gfcommunity.cpp gfcomputation.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=cdgreen
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(INCLUDES) $(OBJECTS) -W $(LIBS) $(LDFLAGS) -o $@
.cpp.o:
$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
clean:
rm -rf *o $(EXECUTABLE)
%%%%%%%%%%%%%%% Makefile End %%%%%%%%%%%%%
I use the mkl link line advsor to get the link info I need, which is as follows:
“ use this link line:
-Wl,--start-group $(MKLROOT)/lib/intel64/libmkl_intel_ilp64.a $(MKLROOT)/lib/intel64/libmkl_core.a $(MKLROOT)/lib/intel64/libmkl_sequential.a -Wl,--end-group -lpthread –lm
Compiler options:
-DMKL_ILP64 -m64 -I$(MKLROOT)/include “
I have made these changes in my makefile as shown above.
In my code, in “gfcomputation.cpp” I use several mkl function, such as dgetrf_, dgetri_, cblas_dgemm etc.
When I run the make file, it can generate object files well, but there are always link errors:
“
gfcomputation.o: In function `gfcomputation::matrixinv(double*, int)':
gfcomputation.cpp:(.text+0x1891): undefined reference to `dgetrf_(int*, int*, void const*, int*, int*, int*)'
gfcomputation.cpp:(.text+0x18b9): undefined reference to `dgetri_(int*, void const*, int*, int*, void const*, int*, int*)'
gfcomputation.o: In function `gfcomputation::matrixmulti(double*, double*, double*, int, int, int)':
gfcomputation.cpp:(.text+0x19b3): undefined reference to `cblas_dgemm(CBLAS_ORDER, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, int, int, int, double, double const*, int, double const*, int, double, double const*, int)'
gfcomputation.o: In function `gfcomputation::sparsematrixmulti(double*, double*, double*, int, int, int, int)':
gfcomputation.cpp:(.text+0x1c5b): undefined reference to `mkl_dcoomm(char*, int*, int*, int*, double*, char*, double*, int*, int*, int*, double*, int*, double*, double*, int*)'
collect2: ld returned 1 exit status
make: *** [cdgreen] Error 1
”
I searched on the web and it seems lots of people had this problems, but there’s no direct solutions to this problem. I also check the link example in mkl userguide, it seems my makefile is ok.
I have been struggling with this for several days and really need someone’ help. Thanks!
C.J.