Linking fortran dynamic libraries with elab
Problem
Fortran does not provide exception handling, therefore if the fortran dll aborts then elab will abort.
Solution
Exception handling in fortran can be provided through linking the fortran code to a C dll as following:
-
create a C dll that exports one function called say my_throw() void my_throw() { throw; } In a more advanced version of my_throw a message could be passed as argument
-
load the C dll from Fortran and the address of function my_throw()
-
call my_throw() from fortran whenever necessary. This will call create an exception, which will be traced by elab and therefore elab will not crash a) Every fortran "stop" command (if any) should be replaced with "call my_throw" b) In every Fortran input/output command (if any) the specifier IERR should be used and a subsequent call to my_throw, if an error occurred. c) Every logical control set by the programmer that informs him that something went wrong (e.g. iterations did not converge) should be followed by a call to my_throw. d) The programmer should make sure that segmentation faults do not exist in his fortran code.