Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

How to link Libraries with ifort


Hello, I'm trying to link libraries to my Fortran programs with ifort.

A few days ago, I posted a thread in the MKL subforum because I thought that it was a problem referring to the MKL.

My main platform is Linux 64-bit now. But, I suppose that my problem doesn't has to do with the platform specifically.

Now, I have the same problem with OpenMP on Linux that I've been having with the MKL on macOS for a few days. I have read the documentation and I have executed the "" script and the "" script with the supplied arguments. I have executed these script several times both as normal user and as root to become sure that it is done correctly.

I can compile all my source codes with the "-mkl"-argument or with the "-qopenmp"-argument without issues. But, when I try to execute the built binaries it returns error these messages:

error while loading shared libraries: cannot open shared object file: No such file or directory


error while loading shared libraries: cannot open shared object file: No such file or directory

On Linux neither "-qopenmp" nor "-mkl" work. On macOS "-qopenmp" works but "-mkl" doesn't work. The error message which I get on macOS is similar to the submitted examples from Linux. Thus, it seems that the link in the binaries don't match with the location of the library-file.

Of course, I have already searched for these filenames and I have successfully found them at





Undeliberately, these error messages only reveal the filename but they do not reveal the complete path where the library file is failed to be loaded from.

So, I could solve this problem by either linking the real location of the library when compiling or by finding out the entire path where the library is assumed to be such that I can link it manually.


Sorry, but I am a complete beginner. I would be glad to find a least one of the supposed solutions.

0 Kudos
2 Replies
New Contributor II

Here is how I tell the OS how to find libraries.  (I use the bash shell, and you probably do too.  If not you'll have to do something similar but different.)

Edit the file $HOME/.bashrc  (i.e. edit the file .bashrc in your home directory.)

At the end of the file, add these two lines:



Then save the file.  What the above does is add a couple of paths to those already in LD_LIBRARY_PATH.

You now have to reload .bashrc.  You can do this either by logging out and in again, or by typing at the command line:

source ~/.bashrc

You can see what LD_LIBRARY_PATH looks like by typing:



0 Kudos

Thank you very much for your answer. But fortunately I've found the solution myself.

The environment settings are simply temporarily. Sorry that I couldn't image this before. I did not recognise this because I had multiple terminal windows on multiple desktops. I always have executed the ifort compiler from a different shell than where I had set the environment variables.

However setting the environment variables wasn't necessary on macOS before. I remember that I had installed the ifort compiler locally at /Users/pascal/intel/ first but I did not install the entire Intel Parallel Studio Composer Edition then which I've installed later gobally at /opt/intel/. Perhaps this is because I didn't need to set these variables on my Mac explicitly.

Thanks to your reply I have successfully set these environment settings to be automatically loaded when starting a shell. Thank you!

0 Kudos