Hi,
I have a C++ library wrapped to a FORTRAN code with Swig-Fortran: let’s call this library MyLibC…
This wrapping works just fine so far, my Fortran code can create an Object from MyLibC and use it.
Things become a bit complicated as now the Fortran code is encapsulated into a C++ Singleton. So, Imagine a C++ script linked to the Fortran code: This main C++ script calls various (bound) Fortran functions and routines, and this still works fine.
Difficulty comes when trying to share an object created by the Fortran code (an object from MylibC) with the main C++ script. My intuition (and hope) is that I could use a C_PTR maybe for this, but I really don’t know.
My object in the Fortran code is declared like this : TYPE(SWIGTYPE_p_Mylib__MylibFieldDouble) :: FIELDG.
How can I share this object with the main C++ script, please ?
Thank you in advance for any help… Pierre
What do you mean by “script” when it comes to C++?
You may be best off trying to consume the " C++ library" directly from “the main C++ xx” rather than trying to “trying to share an object created by the Fortran code.”
By the way, the language since the 1991 publication of its ISO IEC standard revision goes by Fortran, not FORTRAN.
And note the Fortran standard supports interoperability with a companion C processor, but there is no recognized support with C++. Thus you are constrained with a middle layer of C, via “extern C” in C++ and the facilities toward interoperability with C and its requirements in Fortran.
If you retain a necessity to go the Fortran route in your C++ code(s), if you can mock up a scenario of the data involved and what operations (methods) need to be performed on the data, readers can suggest some code design options. In the meantime, you can review this thread closely for some of the options toward working with Fortran from C++.
You’re right, I shouldn’t have used the word ‘script’ : but actually, it happens that swig can generate APIs of a given C++ library for many languages, as Python ; this is why I have made the confusion).
I know it sounds strange to take a Fortran library, wrap it to make it usable in the Fortran code, and then transfer the data to the C++ supervisor… Wrapping the library has been done long ago and it was necessary. The C++ encpasulation of the Fortran code is recent, and we need to access these data from the C++ code (and we dont want to redo all the process we have done on the Fortran Objects).
OK for the ‘C’ layer between Fortran and C++: by the way, this is the way SWIG works for doing the wrapping between the C++ library and the Fortran code.
Since this post, we have realised it is not easy to achieve our goal and we start to think of redoing all the Fortran process in C++ . It’s a long work but it will be more robust.
Thanks for the link to the thread, I am going to read this in detail…