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

Need guide on project structure combining C++ main +functions with Fortran subprograms

Anthony_Richards
New Contributor I
816 Views

Please can you point me to a guide showing, in the simplest way possible, the steps required to set up a solution containing a C++ main (+ a few  C++ functions) program project that calls a set of Fortran functions in a Fortran project so that they can be easily and straightforwardly combined into a 32-bit application that will run on a 64-bit platform? I have VS2012  and IVF 2013 SP1 32-bit and X64 compiler installed. Thanks in advance.

0 Kudos
5 Replies
Anthony_Richards
New Contributor I
816 Views

p.s. From the IVF Compiler User and Reference guide in the VS2012 Help viewer window I have printed off and am trying to absorb

Configuring Visual Studio for Mixed-Language Applications

and

Building Intel® Fortran/C Mixed-Language Programs (Windows* OS)

but would appreciate other useful tips and how to avoid pitfalls.

0 Kudos
Steven_L_Intel1
Employee
816 Views

Start with How do I configure Microsoft Visual C++ for developing mixed Fortran-C applications?

Then here's what I usually do:

  • Create a new C/C++ executable project/solution to hold the main program
  • Add to the solution a Fortran static library project
  • Right click on the C project, select Project Dependencies. In the Dependencies tab, check the box for the Fortran project. Note that in VS2013 it's Project Dependencies > Build Dependencies.
  • Now comes the annoying part. A MSVC project no longer links in output libraries from dependent non-MSVC projects. So you have to add the .lib output of the Fortran project to the C project. You could do this in the Linker > Input > Additional Dependencies property - you'll need to specify the full path to the library and take care to use $(PlatformName) to distinguish 32 and 64-bit (also debug and release). Note that by default, any change you make to a property affects only that configuration, so you may need to select "All Platforms" or "All Configurations" (or both).

That should do it.

There's nothing special about running a 32-bit application on a 64-bit platform. It just works.

0 Kudos
Anthony_Richards
New Contributor I
816 Views

Thanks Steve, I printed off and used the document you recommended. I had guessed that I would have to create a static library of all my
Fortran files, and I did what you recommended, and after some trial and error I have two 32-bit .EXEs running OK on my 64-bit Windows 8 platform

There was one wrinkle which I am not quite clear how I solved it, but it involved making the dialog box resources included in a .RC resource file available to the C++ .EXE when it was being built while still having it available to the Fortran code for updating the RESOURCE.H file and subsequently regenerating the RESOURCE.FD include file needed when compiling the Fortran. On one build, I tried using the .EXE and the first dialog resource was not found, so I guessed that the resources had not been added either to the static library used to build the .EXE. or to the .EXE when it was being built.
How would you do it (add dialog resources)?
Thanks again.

0 Kudos
Steven_L_Intel1
Employee
816 Views

This is not something I have played with. My understanding is that one has to link to the .res file created by the resource compiler. I don't think one can put this in a static library, but I'm not sure. I suppose you'd have to add the .res as an additional link dependency to the C project.

0 Kudos
Anthony_Richards
New Contributor I
816 Views

Thanks for the tip about using the .RES compiled resource. I have my mixed-language executable working now thanks, Although I am still a bit confused as to where to correctly put the resource file (into the static library project or into the main C++ project), so I put it into both!

0 Kudos
Reply