user7698505
user7698505

Reputation:

Compile Fortran program with IFORT and using object files (i.e. .lib) compiled in Microsoft Visual Studio

I have a basic question that I cannot find the answer to even after searching the web many times.

Is it possible to compile a Fortran program by IFORT that uses (as dependencies) object files (i.e. .lib) that were compiled by Microsoft Visual Studio C?

Upvotes: 1

Views: 751

Answers (1)

Steve Lionel
Steve Lionel

Reputation: 7277

Yes, it is possible, and is even rather easy. You have several options for how to do this:

  • Add the MSVC library project to your Fortran Visual Studio solution and then use Project > Dependencies to add the C project as a dependent of your Fortran project *does not work if the C project creates a DLL)
  • Add the .lib from the C project to the Fortran project as if it were a source file
  • Name the C .lib in the Linker > Input > Additional Dependencies project property.

I generally recommend the first choice, as it means you don't have to fuss with different settings for Debug and Release projects. You do need to make sure that the C library is built to specify the same run-time library type (Debug vs. Nondebug, DLL vs. Static) as the Fortran project. This is in the Code Generation property page for C.

There is a worked example "Fortran Calls C" in the Intel Parallel Studio XE for Windows Sample Bundle.

You'll also need to understand how to call a C procedure from Fortran and ensure that the C arguments have compatible Fortran types. It works best if you make use of the Fortran standard's "C interoperability" features.

Upvotes: 1

Related Questions