I have a large mixed C / Fortran code base that is now compiled using Intel tools on Windows. I was asked to port it to GNU tools, on Linux. More or less at random I chose version 4.8.
When a C function is called from Fortran, interoperability often looks like this:
// C code: void PRINTSTR(char *str, size_t len) { for(int ii = 0; ii < len; ii++) { putchar(str[ii]); } putchar('\n'); } !Fortran code: program test implicit none call printstr("Hello, world.") end
The Intel Fortran compiler always generates uppercase characters, so this works great. But the GNU Fortran compiler always generates lowercase characters, and therefore a linker error occurs.
The GNU Fortran compiler had an option called -fcase-upper that made it generate uppercase characters, but it seemed to be too customizable for everyone well, and it was removed (I don't know for sure).
You can use the ISO_C_BINDING tool to force the compiler to generate a case-sensitive name:
program test interface subroutine printstr(str) bind(C, name='PRINTSTR') character :: str(*) end subroutine end interface call printstr("Hello, world.") end
This fixes the linker error, but it changes the order in which string parameters are processed; the length parameter is no longer provided. Therefore, to use this method, I would not need to add interface definitions for each function that currently works this way, but I would also need to change how the lines are processed for each call to such a function, making sure that all lines are zero completion.
I could go through and make all of these functions lowercase, but of course, the Intel compiler still generates uppercase characters to break the existing assembly.
Since there are ~ 2000 such functions, this seems like an unrealizable amount of work. So my question is this: how can I resolve link errors without changing the semantics of a function call and without breaking an existing assembly using Intel compilers?