views:

49

answers:

1

What is the best practice when doing a mixed language library where the library language requires a runtime initialization?

I have a problem where I'd like to create a certain library in Fortran which is to used from C++. I'd want to preserve platform independence and compiler independence if possible. Now, the two compilers I have played with, G95 and GFortran both require that the main application calls certain compiler-specific initialization routines to properly set up the runtime before using the library. These functions have different names and signatures depending on the compiler (for G95 the function is void g95_runtime_start(int argc, char *argv[]) )

I'm using CMake to manage the project and the library subproject is a static library. Do I somehow in my cmake file for the main application have to dig out which fortran compiler is used for the library subproject and then let CMake create a define in the main project so that I can conditionally compile the main app with either init routine? It feels very awkward. Is there a better way?

+1  A: 

There is support for the name mangling and alternative mains (AC_FC_MAIN) in autoconf. I know there were some discussions on this in the cmake group also, so it might be available in the FortranCinterface module. However I could not find any docs on that. I prefer to work with autotools over cmake because these type of issues are already solved and well documented.

DiggyF