Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
5 Views

Can't link MKL to project

Jump to solution

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

Accepted Solutions
Highlighted
Black Belt
5 Views

In VS 2017, the list of

Jump to solution

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

0 Kudos
17 Replies
Highlighted
Black Belt
5 Views

The approach that you have

Jump to solution

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 .

0 Kudos
Highlighted
5 Views

I used the link advisor and

Jump to solution

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.

0 Kudos
Highlighted
Black Belt
5 Views

Add "Use Lapack95" to your

Jump to solution

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.

0 Kudos
Highlighted
5 Views

It doesn't work. I still get

Jump to solution

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

 

0 Kudos
Highlighted
Black Belt
5 Views

Please describe the steps

Jump to solution

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.

0 Kudos
Highlighted
5 Views

Here are the things I did...

Jump to solution

Here are the things I did...

0 Kudos
Highlighted
5 Views

In the program itself I did

Jump to solution

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

0 Kudos
Highlighted
5 Views

Here is the error that I'm

Jump to solution

Here is the error that I'm getting.

0 Kudos
Highlighted
Black Belt
5 Views

You did not add the USE

Jump to solution

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

0 Kudos
Highlighted
5 Views

This is the updated code.

Jump to solution
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

 

 

0 Kudos
Highlighted
Black Belt
5 Views

There are many places to

Jump to solution

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.

0 Kudos
Highlighted
5 Views

It's very frustrating. My

Jump to solution

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.

0 Kudos
Highlighted
Black Belt
5 Views

Quote:hollander, yair wrote:

Jump to solution

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.

0 Kudos
Highlighted
Black Belt
5 Views

Please create a ZIP file of

Jump to solution

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

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
5 Views

Steve, how can I make the zip

Jump to solution

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

Wait...youtube...

 

0 Kudos
Highlighted
Black Belt
6 Views

In VS 2017, the list of

Jump to solution

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

0 Kudos
Highlighted
5 Views

mecej4, I'm sending you

Jump to solution

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.

0 Kudos