Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
49 Views

Link failure with Clang

Hello,

I'm trying to link MKL with the clang compiler (on Linux), and I'm using the following link-line:

clang-5.0 -std=c++17 -O3 -Wall -Wextra 
  -Wno-missing-braces -Wunreachable-code -stdlib=libstdc++ 
  -fopenmp -msse2 -msse3 -msse4 -D EIGEN_USE_MKL_VML -m64 
  -O3 -DNDEBUG -lstdc++ -fopenmp -lpthread 
  -Wl,--start-group /path/to/mkl/libmkl_intel_ilp64.a /path/to/mkl/libmkl_gnu_thread.a 
  /path/to/mkl/libmkl_core.a -Wl,--end-group -lgomp -lpthread -ldl [objects] -o [executable] -lm 

I get the following errors:

... undefined reference to `MKL_malloc'
... undefined reference to `MKL_free'
... undefined reference to `feastinit'
... undefined reference to `dfeast_sygv'

I followed the instructions from the link advsior for the GCC compiler. This seems as if the library I provided for mkl_core is either somehow not being linked correctly or does not contain the references to "MKL_malloc" (my code has "mkl_malloc" instead, so I'm not sure why it's trying to find this different spelling).

What am I missing? Thanks!

0 Kudos
6 Replies
Highlighted
Beginner
49 Views

Here's the log output when I run that previous command with the -v (verbose) flag:

 "/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr 
-m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 
-o [executable] /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crt1.o 
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crti.o 
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/crtbegin.o
 -L/path/to/intel64 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0 
-L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu 
-L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu
 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../.. -L/usr/lib/llvm-5.0/bin/../lib -L/lib -L/usr/lib 
-l:libmkl_core.a -l:libmkl_intel_ilp64.a -l:libmkl_gnu_thread.a -lgomp -lpthread -lm -ldl
[objects] -lm -lstdc++ -lomp -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed
 /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/crtend.o 
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crtn.o

 

0 Kudos
Highlighted
Moderator
49 Views

pls try to add -DMKL_ILP64 option in the case if you need to link with ILP64 API

0 Kudos
Highlighted
Beginner
49 Views

I added that option, but I still get the same error :( thanks for catching that though.

0 Kudos
Highlighted
Beginner
49 Views

My first guess is that since ld is a one pass linker, you need to put the mkl libraries at the end of the link line.  Your libraries will be passed first, and tell the linker which symbols it needs to be resolved.  Then the linker will pass the intel libraries and pick out the symbols it needs.

If you put your objects in the start-group and the end-group, then the linker will make multiple passes in trying to satisfy the symbols.  The reason MKL has this is due to possible circular dependencies between the static libraries.  This would fail in a one pass linker, unless the libraries were placed multiple times on the same link line.  For example:
libA.a libB.a libA.a
would be required to fix the circular dependency without the start-group and end-group options.

 

 

 

 

 

0 Kudos
Highlighted
Beginner
49 Views

I gave your suggestion a try, by duplicating the libmkl_core.a (as well as the others), but that doesn't work. Is there a recommended linker for MKL?

0 Kudos
Highlighted
Beginner
49 Views

The linker is usually part of the system, unless clang has its own.  I am seeing the symbols here:

nm libmkl_intel_ilp64.so | grep -i malloc
00000000001b2ff0 T cblas_xerbla_malloc_error
000000000063c1d0 T fftwf_malloc
00000000006383e0 T fftw_malloc
000000000013d3e0 T mkl_malloc
000000000013d3e0 T mkl_malloc_
000000000013d3f0 T MKL_malloc
000000000013d3e0 T MKL_MALLOC
000000000013d400 T mkl_serv_iface_malloc
                 U mkl_serv_malloc

 

Of course you are using the .a file instead of the .so.

0 Kudos