How to compile C++ to Java Bytecode


Is it possible to compile C++ code to Java bytecode?

It seems possible through nestedVM, has anyone ever tried it? I have checked out the code from nestedVM to discover that it only builds with gcc 3.3.6 and I have gcc 4.1 on my machine,

My goal is to effortless translate c++ code to Java Byte code. There is a tool (commercial) called Tangible that is supposed to convert C++ code to Java code. It, however, does not work perfectly.

Hence, I was thinking that if I could translate the C++ code to JavaByte code I would fix my situation.

Is there a way that GCJ or GCC can be used to do the job? Seems that the folks who created nestedVM figure that compiling the C++ code to the MIPS architecture would be the way to go to convert that into Java bytecode that is 100% java compatible.

Any thoughts on how to fix that?

Who is Participating?
CarlosScheideckerAuthor Commented:
I have tried 2 solutions:

The first I have bought the Tangible tool, I would say avarage.

The second was nestedvm. That works, but the code looks like the assembler code for Java. Yes the code work but no one can read it.

HI, this is not possible, if you want to convert C++ (byte)code to (byte)java code you have to reprogramm the code
You'd probably find it easier to compile the C++ to a shared library and then load that with JNA in Java
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Are you looking to convert it to Java bytecode because you want the security of knowing the code is being verified before execution or to gain interoperability with Java?

If you're looking for the security and verification elements of Java you might be better looking at Google's new "native client" platform:
This allows C++ code to be run in a sandboxed environment similar to Java's VM.

If you're looking for the code to be interoperable with other Java code then you'd be better off just compiling your C++ code as a native library and loading it with JNI ( or

Compiling direct from C++ to Java bytecode would be a major undertaking and I'm not aware of anyone working on that today.

CarlosScheideckerAuthor Commented:

Nestedvm does that by compiling the C++ code to mips and then converting it to java bytecode. I am a little stuck on building the tool but I am almost there.
CarlosScheideckerAuthor Commented:
None of the above solution worked. So I have proposed two that worked.
>> That works, but the code looks like the assembler code for Java.

IOW - it's bytecode
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.