VS 2012 mixed c++ and fortran static library

VS 2012 mixed c++ and fortran static library

Today we are developing our software using scons as build tool. Which works fine, but is far away from in an integrated solution. Below scons we use the Intel Composer 2013 suite. Which works fine too. For any reason whatsoever we have libraries that contain Fortran, C and C++ code. As said before it works fine with scons. No trying to migrate to the integrated VS solution, I can create a C++ static library or a Fortran static library, But I have no clue how to have both mixed into one one. Sure I can add my foreign element to that project, but it is not compiled there. For sure I can add a custom rule, but that is not the integrated solution.

Does anybody see a solution ?

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

The task of building a library from multiple source languages at the command line using Scons seems to be straightforward. I had not heard of Scons until I saw this post, so I cannot respond to your question concerning the use of Scons in combination with Visual Studio.

In Cygwin-32 under Windows 7-64, the following SConstruct script produced the object library libmylib.a from source files myc.c and myf.f:

env = Environment()
env.Library(target = 'mylib.a', source = ["myc.c","myf.f"])

The build under Cygwin used gcc and gfortran as the compilers, so you would have to specify your choices of alternative compilers.

If you have a native Windows installation of Python and SCons, or because you have been using SCons with the Intel compilers, you may already have scripts that choose those compilers.

Again using scons from commandline and having mixed libraries is not an issue.We do this every day.
The issue is, if you want to get rid of scons and use VisualStudio as the only toolchain, you will face the problem of mixed libraries.

You need to do two things here. 1) Make the C library project a dependent of the Fortran library project. 2) In the Fortran project, set the property Librarian > General > Link Library Dependencies to "Yes". When the Fortran project builds, it will merge in the library from the C project.

This won't work the other way around because the Microsoft C++ project system won't do anything with non-C++ dependent projects in VS2012 (and I think in VS2010.)

Retired 12/31/2016

Leave a Comment

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