Can't get fortran 90 program to link to mkl libraries

Can't get fortran 90 program to link to mkl libraries


I'm pretty much a newbie with this so I hope this question won't look too stupid. I'm trying to call the Intel DFT subroutines in a Fortran 90 program. So I first make the object file:

ifort -c Test_FFTW3.f90

then link it:

ifort -L/opt/intel/mkl721/lib/em64t Test_FFTW3.o

I chose em64t as I am running on an Opteron machine.

However, I get back:

IPO Error: unresolved : dzfft1d_
Referenced in Test_FFTW3.o
Test_FFTW3.o(.text+0x488): In function `MAIN__':
Test_FFTW3.f90: undefined reference to `dzfft1d_'
Test_FFTW3.o(.text+0x4a7):Test_FFTW3.f90: undefined reference to `dzfft1d_'

If I try using:

ifort -L/opt/intel/mkl721/lib/em64t -lm Test_FFTW3.o

I get the same error.

I tried using ld to link the object file:

ld Test_FFTW3.o -L/opt/intel/mkl721/lib/em64t -lmkl -lguide -lm

But I get even more error messages:

ld: warning: cannot find entry symbol _start; defaulting to 0000000000400368
Test_FFTW3.o(.text+0x8): In function `MAIN__':
Test_FFTW3.f90: undefined reference to `__intel_proc_init'
Test_FFTW3.o(.text+0x2f):Test_FFTW3.f90: undefined reference to `for_set_reentrancy'
Test_FFTW3.o(.text+0xb2):Test_FFTW3.f90: undefined reference to `for_alloc_allocatable'
Test_FFTW3.o(.text+0x1be):Test_FFTW3.f90: undefined reference to `for_alloc_allocatable'
Test_FFTW3.o(.text+0x33b):Test_FFTW3.f90: undefined reference to `for_alloc_allocatable'
Test_FFTW3.o(.text+0x449):Test_FFTW3.f90: undefined reference to `for_alloc_allocatable'
Test_FFTW3.o(.text+0x51a):Test_FFTW3.f90: undefined reference to `for_open'
Test_FFTW3.o(.text+0x58f):Test_FFTW3.f90: undefined reference to `for_open'
Test_FFTW3.o(.text+0x61f):Test_FFTW3.f90: undefined reference to `for_open'
Test_FFTW3.o(.text+0x679):Test_FFTW3.f90: undefined reference to `for_write_seq_fmt'
Test_FFTW3.o(.text+0x6d3):Test_FFTW3.f90: undefined reference to `for_write_seq_fmt'
Test_FFTW3.o(.text+0x700):Test_FFTW3.f90: undefined reference to `for_close'
Test_FFTW3.o(.text+0x72d):Test_FFTW3.f90: undefined reference to `for_close'
/opt/intel/mkl721/lib/em64t/ undefined reference to `pthread_atfork'

Does anyone have any idea on how to solve this linking problem? I have a suspicion it's some simple option I left out, but I can't work out what it is.

Thanks very much!

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

In addition to specifying the -L path, you must give the -l option for the specific library you use, e.g. append -lmkl_em64t to your link command. There should be examples of this in the documentation. If you want to use -lmkl, you must put a symlink to the actual library in an appropriate place in your library path. It's certainly annoying that ifort reports such errors as IPO errors.
In order to use the em64t libraries, you must compile with the 64-bit em64t version of ifort (the one with fce in the installation path). If you are using the 32-bit ifort, ld will ignore the 64-bit objects in the em64t libraries.
You would also require an option which specifies linking against threading libraries. With ifort, -openmp works as shorthand for -lguide -lpthread. You would not normally use -lm when using a Fortran compiler to drive a link.
It's possible to invoke ld directly, but you must specify the correct libraries, including those which ifort would pass to ld.


Thanks very much for the reply! However, when I add -lmkl_em64t ie.

ifort Test_FFTW3.o -L/opt/intel/mkl721/lib/em64t -lmkl_em64t

I get even more massive errors. For example,

/opt/intel/mkl721/lib/em64t/libmkl_em64t.a(def_zfft1d_omp.o)(.text+0x702): In function `_mkl_dft_def_zfft1d_197__par_loop1':
head_zfft1d_omp.c: undefined reference to `__kmpc_for_static_init_4'

I suspect that this is because there is no in /opt/intel/mkl721/lib/em64t. Here is the directory listing for /opt/intel/mkl721/lib/em64t.

libguide.a libmkl_lapack.a libmkl_em64t.a libmkl_solver.a

I did not install the intel compilers and mkl myself so I am not sure what options they chose. Am I missing the required libraries in /opt/intel/mkl721/lib/em64t for the linking to work? I checked with the list of files in the usage guide, mkluse.htm, and libmkl_scalapack.a, libmkl_blacs.a, libmkl_blacs_intelmpi.a, libmkl_scalapacktesting_intel.a and libmkl_scalapacktesting_gnu.a are missing. Should I attempt to reinstall the compilers and mkl myself?

As to why I tried ld as well as the -lm option, the usage guide for mkl states that:

To use LAPACK and BLAS software, you must link the following libraries: LAPACK, processor optimized kernels, threading library, and system library for threading support. If you want to use FFT/DFT, you may add "-lm" in your link option. Some possible variants:

ld myprog.o -L$MKLPATH -lmkl_lapack -lmkl_ia32 -lguide -lpthread
IA-32 applications static linking of LAPACK and kernels. Processor dispatcher will call the appropriate kernel for the system at runtime.
ld myprog.o -L$MKLPATH -lmkl_ia32 -lguide -lpthread -lm
IA-32 applications static linking of BLAS and FFT/DFT. Processor dispatcher will call the appropriate kernel for the system at runtime.

So I should always use ifort to do the linking instead?

Yes, you should use ifort to link, if you have been using ifort to compile. As I stated, that saves you from having to know specific Fortran support libraries, as well as taking care of -lm.
You must make your own choice whether to link the static or dynamic mkl libraries. In principle, you could use either -lmkl_em64t (the static library) or -lmkl (a dynamic library). We normally use the static ones. The fact that you get unresolved references from the mkl library when you don't specify the required OpenMP support library does indicate that you did actually link the static mkl library. You have got far enough to indicate that you do have an em64t installation of ifort to match your choice of em64t mkl, and to show that you actually invoked an MKL function which is OpenMP parallel.
Since you have ifort installed, you could get the libguide either from the ifort or the mkl library directory. As you have an out of date mkl, there might be an advantage in getting the ifort one, in case your ifort is more up to date, but this is outside the scope of the documented linking instructions, which you seem to have difficulty following.
Those other mkl libraries would come with the cluster MKL. I don't think you have shown any indication you are trying to use anything but the standard MKL functions. Even if you are running on a cluster, you don't need the cluster MKL if your MKL functions work local to the node.
I have noticed myself the placement of the redundant copies of lapack libraries. I don't think there is any purpose for the lapack32 library in the em64t directory.
The stuff about picking a kernel at runtime applies primarily to the 32-bit version. There, you would get the SSE2 version of MKL only if the CPU is recognized as genuine Intel with SSE2 support. MKL would always assume full SSE2 support under x86-64; it might conceivably use SSE3 instructions when a genuine Intel 64-bit CPU is detected.

Leave a Comment

Please sign in to add a comment. Not a member? Join today