Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm learning PETSc and trying to make the examples written in C. However, when I use the provided makefile, I get the following error:

/usr/bin/ld: cannot find -lmkl

When I check in the mkl/lib directory, I find that none of the .a or .so files are called libmkl.

Do I need to recompile PETSc to have the built-in makefiles link to MKL?

Which library file should I link to if not lmkl?

share|improve this question
up vote 3 down vote accepted

This seems like a linking problem with Intel's Math Kernel Library. You have many questions, so I will try to address each one.

In general, when there is a linking problem, especially "cannot find -lfoo", check the search directories. These are options that are usually specified with -L such as "-L /path/to/libraries". In your case, the intel compilers should usually accept the "-lmkl" option which internally specifies the location to the libraries. This does not solve your problem, though.

Since you are usually PETSc, and you are getting this error, it means that you are trying to switch the compilers or BLAS/LAPACK library after building PETSc. This is not supported. So, yes, you will need to reconfigure and rebuild specifying the Intel compilers and MKL. See the installation help for more information.

There are many libraries that need to be linked so that you can use Intel's MKL. Intel even made a helpful page to build the command-line link option.

share|improve this answer
As far as switching compilers or the LAPACK libarary, would updating either to a new version suffice to cause problems? – Dan Dec 20 '11 at 23:37
Yes, because if the new compilers or LAPACK library aren't application binary compatible (ABI) then the linking will not work, which is what you're seeing. Plus, Intel is notorious about changing the linking commands between versions. – Sean Farley Dec 21 '11 at 3:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.