java 为 JVM 编译 C++

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4221605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:23:02  来源:igfitidea点击:

Compiling C++ for the JVM

javac++compiler-construction

提问by knpwrs

When compiling C++ you of course use a compiler for the target platform you want to compile for. Is there a C++ compiler that targets the JVM (so instead of using the Java "native" interface C++ code is compiled to Java byte code)?

编译 C++ 时,您当然要为要编译的目标平台使用编译器。是否有针对 JVM 的 C++ 编译器(因此 C++ 代码不是使用 Java“本机”接口而是编译为 Java 字节码的)?

采纳答案by ephemient

NestedVMprovides binary translation for Java Bytecode. This is done by having GCC compile to a MIPS binary which is then translated to a Java class file. Hence any application written in C, C++, Fortran, or any other language supported by GCC can be run in 100% pure Java with no source changes.

NestedVM为 Java 字节码提供二进制翻译。这是通过让 GCC 编译为 MIPS 二进制文件,然后将其转换为 Java 类文件来完成的。因此,任何用 C、C++、Fortran 或 GCC 支持的任何其他语言编写的应用程序都可以在 100% 纯 Java 中运行,无需更改源代码。

回答by KIC

As I have answerd on this similar SO questionthere is a new kid in town called gcc-bridge. It's a maven plugin and supports all the gnu laguages like c, c++, fortran.

正如我在这个类似的SO 问题上回答的那样,镇上有一个名为gcc-bridge的新孩子。它是一个 maven 插件,支持所有的 gnu 语言,如 c、c++、fortran。