Im going to be rewriting a library from .net to something that can be used on different platforms (Mac, Linux, Windows, Android). But i am also hoping that it can be used accross languages (c#, python, java). My initial thought was that c++ would be the best option. But ive never done something like this so im not sure. Is there a standard way this kind of thing is done?
-
2Do you mean to be able to use identical binaries in multiple different languages, as if it were written in that language? The answer would be no. – Zymus Apr 24 '18 at 02:59
-
1There are already .Net runtimes for all the platforms you list. Many languages have implementations that target .Net IL – Caleth Apr 24 '18 at 10:50
-
@Zymus Not the same binaries, just the same code base. I know that I would need to compile for each platform I am targeting. I'm just trying to avoid being restricted to 1 platform. – 165plo Apr 24 '18 at 18:23
-
@Caleth I had not considered that the different languages would provide a library for working with .Net. I will see if I can find more information on those. – 165plo Apr 24 '18 at 18:24
2 Answers
The "lowest common denominator" language is usually C. Because so much historical code was written in C, including operating systems, many other languages have the facility to call C functions.
That doesn't necessarily mean you have to write in C. In C++, functions can be labelled extern "C"
and are linked as if they were written in C.
Other languages may also have the ability to export functions as if they were written in C.

- 9,167
- 4
- 26
- 33
-
And it takes a lot of knowledge to write portable code in C or C++. There must be summaries somewhere on how to do it. – Frank Hileman Apr 24 '18 at 18:12
-
@Simon B That was my initial thought. Having never written a library with this kind of requirement I wasn't sure if there was a better way to do it. I also know that importing C libraries can be a pain. I know it has been for me in the past using .Net – 165plo Apr 24 '18 at 18:26
-
@FrankHileman The difficulty is also a concern. But I haven't been able to come with a better alternative yet. – 165plo Apr 24 '18 at 18:28
One bigger product I know which targets different languages is AlgLib. According to their FAQ, they use a programming language named AlgoPascal which is cross-translated to C++, C# or Delphi, and supports also different platforms.
(Disclaimer: I have no connections or relationships to that company, and I cannot tell you anything about the quality of their software.)
Unfortunately, the AlgoPascal translator is not publicly available, but at least it shows a way of how such a cross platform/language library can be build. However, I guess this can only be a sensible way if the lib based on such a common source does not need any other platform- or language specific dependencies like some specific UI framework. A math lib like AlgLib is probably well suited for such an approach.

- 199,015
- 33
- 367
- 565