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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.