问题
Is it possible to compile multiple languages together in order to get the best of the different languages.
回答1:
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.
回答2:
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.
回答3:
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,
回答4:
.Net platform is multi-lingual. Parrot is great for mixing Perl, Python, Ruby. What are you trying to do?
回答5:
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.)
回答6:
If you're using .net, you can compile your projects in different languages to netmodules and then link them into a single dll/exe. Visual Studio doesn't support this but msbuild does. The easiest way to get a compile is to edit a COPY of your .csproj file and change the output type to "module" and just run msbuild against it. Then use the "link" command to link your modules into your final exe/dll.
回答7:
Take a look at Swig. It wrapes your C/C++
code so that you can call it from virtually any other language.
来源:https://stackoverflow.com/questions/1912191/compiling-multiple-languages-together