# Sharing a C++ Object created in a Fortran code (with swig) and sharing it with another C++ code

**URL:** <https://fortran-lang.discourse.group/t/sharing-a-c-object-created-in-a-fortran-code-with-swig-and-sharing-it-with-another-c-code/5994>\
**Category:** Help\
**Created:** [June 17, 2023, 4:20pm UTC](https://fortran-lang.discourse.group/t/sharing-a-c-object-created-in-a-fortran-code-with-swig-and-sharing-it-with-another-c-code/5994 "2023-06-17T16:20:23Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [June 23, 2023, 12:43am UTC](https://fortran-lang.discourse.group/t/sharing-a-c-object-created-in-a-fortran-code-with-swig-and-sharing-it-with-another-c-code/5994/2 "2023-06-23T00:43:42Z")

</div>

> [@Bastringue](#):
>
> … I have a C++ library wrapped to a FORTRAN code with Swig-Fortran: let’s call this library MyLibC…
> 
> …  
> Difficulty comes when trying to share an object created by the Fortran code (an object from MylibC) with the main C++ script. …
> 
> How can I share this object with the main C++ script, please ?

@Bastringue ,

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**](https://fortran-lang.discourse.group/t/return-an-array-of-strings-from-fortran-to-c/5100/7) closely for some of the options toward working with Fortran from C++.

---

_[View the full topic](https://fortran-lang.discourse.group/t/sharing-a-c-object-created-in-a-fortran-code-with-swig-and-sharing-it-with-another-c-code/5994)._
