I would like to access Mathematica functions from within a Fortran program. I am unsure how to start (which is probably related to my lack of up-to-date Fortran knowledge). Is it necessary to write a wrapper in C or can I link to the Mathematica library directly. Are there any Fortan examples available which I could start from? How would I compile the Fortran project?


1 Answer 1


Here are a couple of options:

  • You can write a C wrapper function that calls your Fortran code, and use WSTP to export the C function to Mathematica.

    It is relatively straightforward to mix Fortran and C. gfortran is one free compiler. The procedure for linking the compiled C and Fortran object files will depend on your platform, see for example this answer.

  • If your code is Fortran 77, you can use f2c to convert it into ANSI C, and then use WSTP on the C code directly.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.