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

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

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.

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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


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

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

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.

Retired 12/31/2016

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.

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.

Retired 12/31/2016

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!

Leave a Comment

Please sign in to add a comment. Not a member? Join today