多种语言一起编译

发布于 2024-08-15 04:34:51 字数 35 浏览 11 评论 0原文

是否可以将多种语言一起编译,以便充分利用不同语言的优点。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

伤痕我心 2024-08-22 04:34:51

如果编译器和链接器都兼容,那么在单独编译它们之后,绝对可以将它们链接在一起(如果编程适当)。例如:

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

这会编译一个 Fortran 文件,然后编译一个 C 文件,然后使用 GCC 工具套件将它们链接到一个名为 together 的可执行文件中(假设它们正确地相互调用;-)。

Microsoft 的 .NET 是一种同时使用多种语言(C#、F#、IronPython、IronRuby 等)的流行方式。 Visual Studio 将处理编译为兼容代码以及程序集中的连接,但如果您愿意,也可以“手动”完成。

如果“一起编译”意味着在同一个文件中拥有多种不同的语言,这也是可能的,但比较罕见——例如,某些 C 编译器具有扩展功能,可以让您在同一文件中表达“内联”汇编语言。

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.

往事风中埋 2024-08-22 04:34:51

是的,这是可能的,但很大程度上取决于特定的语言。例如,从 Python 调用 C 函数或 C++ 类是例行公事。

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.

牵你手 2024-08-22 04:34:51

在 C 语言中干净地处理 Algol-68 thunk 确实很难。可以,但我不认为我想每天都这样做,

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,

℉絮湮 2024-08-22 04:34:51

.Net 平台是多语言的。 Parrot 非常适合混合 Perl、Python、Ruby。你想做什么?

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

贪了杯 2024-08-22 04:34:51

组合语言的另一个很好的例子是 Java 平台。您可以将 Groovy、Jython、JRuby、Scala、Clojure 和其他语言与 Java 混合使用。不同的语言需要不同的编译器,但通常可以从一种语言调用另一种语言。 Groovy 和 Scala 特别适合互操作。

哦,Java 本机接口 (JNI) 允许您从 Java 调用 C、C++、汇编和其他语言。

(正如其他发帖者所指出的,.NET 平台具有相同的属性。)

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.)

紅太極 2024-08-22 04:34:51

如果您使用 .net,则可以将不同语言的项目编译为 netmodules,然后将它们链接到单个 dll/exe 中。 Visual Studio 不支持此功能,但 msbuild 支持。进行编译的最简单方法是编辑 .csproj 文件的副本并将输出类型更改为“模块”,然后对其运行 msbuild。然后使用“link”命令将模块链接到最终的 exe/dll 中。

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.

蔚蓝源自深海 2024-08-22 04:34:51

看看 Swig。它包装您的 C/C++ 代码,以便您几乎可以从任何其他语言调用它。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文