Compiling multiple languages together

2019-02-19 04:18发布

Is it possible to compile multiple languages together in order to get the best of the different languages.

7条回答
家丑人穷心不美
2楼-- · 2019-02-19 04:25

It's definitely possible to link them together (if suitably programmed) after compiling them separately, if the compilers and linkers are all compatible. For example:

g77 -c one.f
gcc -c two.c
gcc -o together one.o two.o

this compiles a Fortran file, then a C file, then links them together in a single executable named together (assuming they call each other properly;-) using the GCC suite of tools.

Microsoft's .NET is a popular way to use multiple languages together -- C#, F#, IronPython, IronRuby, and so on. Visual Studio will handle the compilations into compatible codes and the joining together in assemblies, but you can also do it "by hand" if you wish.

If by "compiling together" you mean having multiple different languages within the same file, that's also possible but rarer -- for example some C compilers have extensions to let you express "inline" assembly language within the same file.

查看更多
SAY GOODBYE
3楼-- · 2019-02-19 04:26

.Net platform is multi-lingual. Parrot is great for mixing Perl, Python, Ruby. What are you trying to do?

查看更多
看我几分像从前
4楼-- · 2019-02-19 04:26

Take a look at Swig. It wrapes your C/C++ code so that you can call it from virtually any other language.

查看更多
男人必须洒脱
5楼-- · 2019-02-19 04:34

It is really hard to cleanly handle Algol-68 thunks in C. Do-able, but I don't think I'd want to do it every day,

查看更多
等我变得足够好
6楼-- · 2019-02-19 04:38

Another good example of combining language is the Java platform. You can intermix Groovy, Jython, JRuby, Scala, Clojure, and other languages with Java. The different languages require different compilers, but you can generally call from one language to another. Groovy and Scala are particularly well suited for inter-operation.

Oh, and the Java Native Interface (JNI) lets you call C, C++, assembly and other languages from Java.

(The .NET platform shares these same attributes, as other posters have noted.)

查看更多
疯言疯语
7楼-- · 2019-02-19 04:41

Yes, it's possible, but a lot depends on the specific languages. For example, calling C functions or C++ classes from Python is done routinely.

查看更多
登录 后发表回答