How to link Mathematica and Fortran with WSTP?


closed as off-topic by Szabolcs, MarcoB, Daniel Lichtblau, Henrik Schumacher, m_goldberg Jun 7 at 23:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Szabolcs, MarcoB, Daniel Lichtblau, Henrik Schumacher, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ Yes, it is possible, I have done that in the past, but it is tedious. Why not use the simpler approach using LibraryLink ? On which operating system do you want to do that? $\endgroup$ – Rolf Mertig Jun 7 at 10:15
  • 3
    $\begingroup$ Both the LibraryLink and MathLink ( = WSTP) APIs are C language APIs. What you need to figure out is how to call C functions from Fortran. Then you can use the MathLink API from Fortran. However, it might be easier to do the reverse: learn how to call your Fortran library from C and write the glue code in C (either using MathLink, or as Rolf said, using LibraryLink). I suggest you start by learning how to do this in pure C first. Once that's done, hook up the Fortran functions. $\endgroup$ – Szabolcs Jun 7 at 10:25
  • $\begingroup$ At that time I used iso_c_binding, see e.g. [this] (gcc.gnu.org/onlinedocs/gfortran/…). It is possible, but not so easy. $\endgroup$ – Rolf Mertig Jun 7 at 10:41
  • $\begingroup$ @RolfMertig Related. OP insists in calling high level Mathematica functions from FORTRAN. IIRC, this is not possible with LibraryLink. $\endgroup$ – Henrik Schumacher Jun 7 at 11:03
  • $\begingroup$ I am not sure why you tagged this mathematica-online. If that's what you're using, then the simple answer is that it's not possible. Please address Henrik's comment above and explain what you want to do precisely. $\endgroup$ – Szabolcs Jun 7 at 11:38