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

Mixing C++ with Fortran: static or dll?

Pablo_V_1
Beginner
521 Views

Hello, 

Hello, 

I am new using Fortran and Visual Studios. I am developing a C++ code that calls fortran functions and routines. My question is about what is better: to build fortran code as a static library or as dll? In my fortran code I will call IMSL Libraries.

When is best to use each alternative?

Thanks and best regards.

0 Kudos
10 Replies
Steven_L_Intel1
Employee
521 Views

Either one is fine. Static library is simpler.

0 Kudos
Pablo_V_1
Beginner
521 Views

Perfect Steve, thanks.

Another question: When I try to build my solution, I get this error:  

fatal error LNK1104: cannot open file "..\flib\debug\lib.lib". 

I look at additional dependencies properties and there is none. Which could be the problem?

Thanks and best regards, 

0 Kudos
Steven_L_Intel1
Employee
521 Views

Does that file exist? For a mixed C++/Fortran project, you'd need to specify the build dependencies so that the library was built first. Right click on the C++ project and select Build Dependencies > Project Dependencies. Check the box for your flib project.

0 Kudos
Pablo_V_1
Beginner
521 Views

Thanks Steve, I fixed the problem with your advice. 

 

0 Kudos
Pablo_V_1
Beginner
521 Views

Dear Steve,

I understood how to link my fortran functions and subroutines with my c++ code. But how can I call MKL fortran functions, for example as DGEMM, from my c++ code? How must I declare it in my fortran code?

Thanks and best regards. 

0 Kudos
mecej4
Honored Contributor III
521 Views

You may use the C interfaces (Cblas, LapackE) or the Fortran77 interfaces. There are a number of header files to help with the function prototypes, and each routine has an MKL page with details on which header to include, and a description of the argument list.

The MKL examples directory contains many examples of calling MKL routines from C.

0 Kudos
Pablo_V_1
Beginner
521 Views

Thanks. I found MKL examples and I understood how to call MKL routines from C.  I have another problem. When I try to build my solution, in which my c programm call fortran routines/functions, I am having problems when I include "mkl_lapack.fi" I get several errors of these type:

C:\ (...)\mkl\include\mkl_lapack.fi error #5082: Sysntax error, hound END-OF-STATEMENT when expect one of: *<identifier>.

(many errors like this one)

FSUB.F90(81): catastrophic error: too many errors, existing.

I believe that I have a configuration problem. I am using Visual Studios 2008 with Intel Composer XE 2011.

Thanks, 

0 Kudos
mecej4
Honored Contributor III
521 Views

The file mkl_lapack.fi contains interface blocks. Where was your INCLUDE statement positioned in the file FSUB.F90? Can you post the file FSUB.F90 as an attachment?

0 Kudos
Pablo_V_1
Beginner
521 Views

Hi, 

In my FSUB.F90, a fortran library project, I have several functions and subroutines. I can´t post my file FSUB.F90 because I am using remote deskpot and I can´t download my code files. I wrote a part of my file FSUB.90: 

Real*8 Function PRMPI(N,JPICK,AMU,TOL)

INCLUDE 'C:Program Files()x86)\Intel\ComposerXE-2011\mkl\include\mkl_lapack.fi'

USE POTRF

Implicit Real*8 (A-H,O-Z)

....

End

... (other functions and subroutines)

Thanks!

 


 

0 Kudos
mecej4
Honored Contributor III
521 Views

The position of the USE statement is incorrect. It should occur before other declarations. Secondly, there is no module with the name POTRF -- in fact, there are hundreds of MKL routines in the library, but there are only a handful of modules that provide access to those routines. The MKL manual tells you which modules to use. However, if your code is calling the MKL routines with the F77 interface, USE statements for the relevant modules are optional.

In general, when you have faulty code and cannot post it, chances are low for diagnosing the error correctly.

 

0 Kudos
Reply