GCC-Compiled Mixed (C/Fortran) DLL

Follow

Comments

6 comments

  • Avatar
    Cedric Sallaberry

    This is a really nice example. One question

    We have been looking at recompiling our DLLs with gfortran instead of the intel Fortran, which means the !DEC$ commands no longer work. This create an issue mostly for the Reference and Value attributes because we could not find equivalent in GCC.

    Is it possible to compile a DLL in gfortran directly or do we have to use a C Wrapper for that, as you have done?

    0
    Comment actions Permalink
  • Avatar
    Jason

    I think you still need a C wrapper.

    0
    Comment actions Permalink
  • Avatar
    Cedric Sallaberry

    Jason, thanks for the update. We arrived to the same conclusion. 

    We were able to follow your approach and successfuly create a DLL read by GoldSim using the C wrapper. Thanks a lot for the example !!

    1
    Comment actions Permalink
  • Avatar
    Jason

    Cedric,

    I'm glad to know it was successful! Do you mind telling us how you dealt with the !DEC$ issue in your case?

    Thanks,

    Jason

    0
    Comment actions Permalink
  • Avatar
    Cedric Sallaberry

    Jason

    Same as you have done in your example:

    Going with the wrapper in c takes care of the declarations of the variables as values or pointer automatically, so we did not need to use DEC declarations or GCC declarations as reference or values. I spent a good amount of time trying to find equivalent in gfortran compiler for ATTRIBUTES, VALUE and ATTRIBUTES, REFERENCES and could not find any.

    And for the ATTRIBUTES DLLexport, we used bind instead directly in the subroutine name declaration.

    The only additional issue we had was more complex fortran routines in our code, which were not recognized by the c wrapper when transformed into an object. We tried gcc compiler with the option -lgfortran (gfortran library) as recommended online, but it did not work
    .
    we found that another way was to compile the wrapper with gfortran but using the option -lstdc++ (standard c++ library). It is not as elegant (compiling a c file with a fortran compiler), but it worked.


    1
    Comment actions Permalink
  • Avatar
    Jason

    Good to know! Thanks, Cedric. I appreciate that you are willing to share your experience with us. Let us know if you run into any other questions.

    0
    Comment actions Permalink

Please sign in to leave a comment.