Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Can't link MKL to project

hollander__yair
Beginner
591 Views

Hello,

I'm a very basic user of Visual Fortran.

I have a simple Fortran program which I'm trying to run:

PROGRAM matrixinv
IMPLICIT NONE
REAL(8),DIMENSION(3,3)::A,C
INTEGER(4),DIMENSION(3)::IPVT
REAL(8)::RCOND
REAL(8),DIMENSION(3)::V,B
A(1,1)=3.0_8
A(1,2)=2.0_8
A(1,3)=-1.0_8
A(2,1)=2.0_8
A(2,2)=-2.0_8
A(2,3)=4.0_8
A(3,1)=-1.0_8
A(3,2)=0.5_8
A(3,3)=-1.0_8
B(1)=1.0_8
B(2)=-2.0_8
B(3)=0.0_8
call gesv(A,B)
PRINT*,B
END PROGRAM matrixinv

 

This program uses gesv from MKL.

My problem is not being able to link to MKL.

Online instructions tell me to go to Project-> properties -> Fortran -> Libraries -> Use Intel Math Kernel Library -> Sequential (for example).

I do that but I still get: Severity    Code    Description    Project    File    Line    Suppression State
Error        error LNK2019: unresolved external symbol GESV referenced in function MAIN__        Combined_Main.obj        

Why won't the program recognize MKL?

Thank you.

0 Kudos
1 Solution
mecej4
Black Belt
591 Views

In VS 2017, the list of additional libraries (mkl_blas95_lp64.lib mkl_lapack95_lp64.lib mkl_intel_lp64.lib mkl_sequential.lib
) should be inserted into the lower rectangle under Project Properties -> Configuration Properties -> Linker -> Command Line -> Additional Options. 

View solution in original post

17 Replies
mecej4
Black Belt
591 Views

The approach that you have tried is sufficient for Fortran-77 calls, but not for Fortran-95+ calls.

If you wish to call MKL or other subroutines/functions that take optional arguments, have generic names with arguments of different types, etc., you must provide USE statements or interface blocks in your source files and specify that the corresponding BLAS-95 and Lapack-95 libraries be searched at link time. See https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/301587 for a related discussion, and use the MKL Link Line advisor https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor to configure the command lines for compiling and linking.

Posts on this topic are better served in the MKL forum, https://software.intel.com/en-us/forums/intel-math-kernel-library .

hollander__yair
Beginner
591 Views

I used the link advisor and got this:

 mkl_blas95_lp64.lib mkl_lapack95_lp64.lib mkl_intel_lp64.lib mkl_sequential.lib mkl_core.lib

Now what do I do with this line?

Thank you.

mecej4
Black Belt
591 Views

Add "Use Lapack95" to your source, between the Program line and the IMPLICIT line. Open the command window for Intel Fortran for 64-bit targets from the Start menu. Compile using

ifort /Qmkl Combined_Main.f90 mkl_blas95_lp64.lib mkl_lapack95_lp64.lib mkl_intel_lp64.lib mkl_sequential.lib mkl_core.lib

Alternatively, if you are using Visual Studio, first make sure that the project is configured to use MKL (you have probably done this already). Then, select the project Properties pane, add the list of libraries that you obtained from the MKL Advisor to Configuration Properties - Command Line - Additional Options, and check that the target is set to X64. Press OK, and then select Build.

hollander__yair
Beginner
591 Views

It doesn't work. I still get "unresolved external symbol GESV"

 

mecej4
Black Belt
591 Views

Please describe the steps that you tried. 

If you have not done so already, you may need to do "Clean" and then "Build" from Visual Studio.

hollander__yair
Beginner
591 Views

Here are the things I did...

hollander__yair
Beginner
591 Views

In the program itself I did not add anything...

hollander__yair
Beginner
591 Views

Here is the error that I'm getting.

mecej4
Black Belt
591 Views

You did not add the USE statement to your source, as advised in #4 and for the reasons stated in #2. 

hollander__yair
Beginner
591 Views
This is the updated code. Still gives me the error. Do I need to add the advisor line:
"mkl_blas95_lp64.lib mkl_lapack95_lp64.lib mkl_intel_lp64.lib mkl_sequential.lib mkl_core.lib"
Only to the properties->Fortran->command line   or is there another place I need to put it? There are command line options in other "properties" menus like "Linker", "Resources", etc.

PROGRAM matrixinv
Use Lapack95
implicit none
REAL(8),DIMENSION(3,3)::A,C
INTEGER(4),DIMENSION(3)::IPVT
REAL(8)::RCOND
REAL(8),DIMENSION(3)::V,B
A(1,1)=3.0_8
A(1,2)=2.0_8
A(1,3)=-1.0_8
A(2,1)=2.0_8
A(2,2)=-2.0_8
A(2,3)=4.0_8
A(3,1)=-1.0_8
A(3,2)=0.5_8
A(3,3)=-1.0_8
B(1)=1.0_8
B(2)=-2.0_8
B(3)=0.0_8

call gesv(A,B)
PRINT*,B

END PROGRAM matrixinv

 

 

mecej4
Black Belt
591 Views

There are many places to change settings in Visual Studio, and from your posts I cannot see which setting was set incorrectly. The "/c" in the command line in Capture2.jpg should not be there, since it tells the compiler to stop after compiling.

The most straightforward approach at this point, considering that you have a single short source file, is to open an Ifort-x64 command window, and build there using the command line of #4.

hollander__yair
Beginner
591 Views

It's very frustrating. My question is so simple and straightforwrd and I'm sure thousands of people use MKL each day. Why did they make it so difficult...

Where can I find the command window to try and compile from there?

Another question: Would it be a good idea to uninstall and reinstall the Intel Fortran? Could that solve the problem?

Thank you for your help.

mecej4
Black Belt
591 Views

hollander, yair wrote:

It's very frustrating. My question is so simple and straightforward and I'm sure thousands of people use MKL each day. Why did they make it so difficult...

My personal opinions: Intel is not to be blamed; the simple command line approach is completely adequate, but customers seem to prefer to live inside Visual Studio, despite the cost of doing so. VS is a complex MS product with many bells, whistles and knobs. It may work well for large projects. For simple single-file builds, such as yours, it is not only an overkill, it can be a source of much frustration. However, once you get the hang of it, VS can be a useful, if not pleasant, tool to use.

hollander, yair wrote:
Where can I find the command window to try and compile from there?

Windows Start Menu-> Intel Parallel Studio yyyy -> Compiler and Performance Libraries -> Command Prompt with .... -> ... for Intel 64 ...

The exact titles depend on the version of Intel Fortran that you have.

hollander, yair wrote:
Another question: Would it be a good idea to uninstall and reinstall the Intel Fortran? Could that solve the problem?

NO! There is nothing that I have seen to indicate that there is any problem with your installation. It takes many hours to do a complete installation, so do not do that unless it is really necessary.

Steve_Lionel
Black Belt Retired Employee
591 Views

Please create a ZIP file of your entire VS project and attach it to a reply here. Screenshots are not useful.

hollander__yair
Beginner
591 Views

Steve, how can I make the zip file you requested?
Is there a way in VS to do that?

Wait...youtube...

 

mecej4
Black Belt
592 Views

In VS 2017, the list of additional libraries (mkl_blas95_lp64.lib mkl_lapack95_lp64.lib mkl_intel_lp64.lib mkl_sequential.lib
) should be inserted into the lower rectangle under Project Properties -> Configuration Properties -> Linker -> Command Line -> Additional Options. 

View solution in original post

hollander__yair
Beginner
591 Views

mecej4, I'm sending you kisses. It works now !!!!!!!

Steve, you would have probably figured the solution in a minute. Thank you as well.

:-)

I'm happy again.

Reply