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

Conrad__Pascal
Beginner
3,502 Views

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 "compilervars.sh" script and the "mklvars.sh" 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: libiomp5.so: cannot open shared object file: No such file or directory

or

error while loading shared libraries: libmkl_intel_lp64.so: 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

/opt/intel/compilers_and_libraries_2020.0.166/linux/compiler/lib/intel64_lin/libiomp5.so

and

/opt/intel/compilers_and_libraries_2020.0.166/linux/mkl/lib/intel64_lin/libmkl_intel_lp64.so

 

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
gib
New Contributor II
3,502 Views

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:

LD_LIBRARY_PATH="path_to_library1:path_to_library2:$LD_LIBRARY_PATH"

export LD_LIBRARY_PATH

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:

echo $LD_LIBRARY_PATH

 

0 Kudos
Conrad__Pascal
Beginner
3,502 Views

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
Reply