This example model shows how to use an External Element to call a DLL to perform calculations outside of GoldSim. The DLL in this case was compiled using the gcc compiler suite from source code which is mainly written in Fortran. The Fortran portion of the source code is compiled using gfortran. The DLL contains three exposed functions, CustomFortranDLLSum (calculates the sum of two input arguments), CustomFortranDLLProdSum (calculates the sum and the product of two input arguments) and CustomFortranDLLHalf (divides an input argument by 2).
Download the Model File:
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?
I think you still need a C wrapper.
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 !!
I'm glad to know it was successful! Do you mind telling us how you dealt with the !DEC$ issue in your case?
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.
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.
Please sign in to leave a comment.