Mixed language development

Mixed language development

We are using Microsoft Visual Studio 2013 Professional. We then installed the latest version of the Intel Fortran compiler, service pack 1 update 2 I think. Running under Windows 7.

Inside Visual Studio we can create a new Fortran project, such as a static DLL, and add Fortran files to it and they compile and link fine. We can also create Visual Studio C++ solutions, which work fine.

But what if you have a Windows C++ application and you want to compile and link in a few Fortran files? In other words, have one EXE with some Fortran and C++ files compiled and linked into it.

If you add the Fortran files to the C++ project, the right mouse click compile option for them is greyed out and under project settings there is nothing for Fortran, only C++. If we import an old Visual Studio 6 / Compaq Fortran mixed solution (which we are actually trying to convert), then the Fortran files come across as custom compilations but with all the settings missing.

We know there is a way to do this. How?

The only thing we can think of is to, under the solution, have a C++ project, and a Fortran project which is a static library, and then link the Fortran static library into the C++ project. But there are complications such as having to export Fortran methods against which you link, which would not necessary if you link all the OBJ files in one link pass.

What are we missing here?

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

Quote:

benifkc wrote:
We know there is a way to do this. How?

The only thing we can think of is to, under the solution, have a C++ project, and a Fortran project which is a static library, and then link the Fortran static library into the C++ project. But there are complications such as having to export Fortran methods against which you link, which would not necessary if you link all the OBJ files in one link pass.

What are we missing here?

You do it the way that you have described, but I think your estimation of the degree of complication is off.   For example there's no need to export anything - a static library (a LIB file not a DLL - your post mixes terminology a bit) on Windows is pretty much just the packaging into a single file of a heap of object files - the final link of the program proper will behave, pretty much, as if you had just specified the object files directly.

(There might be some differences around symbol search order and what happens if you have multiple symbols with the same name, but this shouldn't be problematic if you have sane code anyway.)

There are some complications - the need to have consistent runtime library specifications between the two projects and perhaps the need to directly reference the Fortran static library in the C++ main program project's link settings, but they aren't that bad.  I can't comment on VS 2013 specifically but give it (Fortran static library + C++ main program) a go and see what happens.

Thank you, we understand. So you just add the Fortran files in a separate project that is of type static library, and then you link the resulting LIB file into the C++ project. As for the link issue, DUMPBIN /SYMBOLS /EXPORTS on the Fortran  LIB file does not list the functions needed. Based on some other Fortran code (using a different make system), it seems that we need to define some bindings or exports and such.

Retired 12/31/2016

Leave a Comment

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