Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool to convert Java source to C++ source [duplicate]

Before someone shoots me down, I am aware of the Java to binary compilers and I'm not after one of those.

I also know there will be no perfect tool that converts everything without any problems. I am aware that missing Java libraries are a major problem; however my source doesn't make use of many Java libraries except for stuff like String and prints. I only want to the tool to create the classes that the Java source references. In the case of the String stuff I am happy to fill in the gaps or fix at a later stage. I just want the tool to do the boring bits so I don't have to do the translation manually.

In the case of required classes etc, I will manually fix those at a later stage but would appreciate a pointer to something that at the very least gets enough of the boring stuff done.

Once again I want the source translated and not a compiler to produce a binary. Basically I want to take some Java stuff and convert it to C++ for later use in other projects.

EDIT ADDITIONAL NOTES

Sorry if I was not clear in my previous parts of this question. I know that Java is very much different from C++. I have some Java code which is mostly filled with processing arrays and bits and has almost no object creation. In a sense it is very self-contained and has few calls to other classes. These classes seem to be prime candidates for conversion; the other stuff will have to be rewritten but at the least some parts are leveraged.

like image 313
mP. Avatar asked Apr 12 '12 01:04

mP.


1 Answers

j2c is one - it will convert Java source code into its rough C++ equivalent.

Obviously there are many caveats that others have mentioned (garbage collection, synchronization, etc) but it will provide a good starting point (and it's open source at that so you can easily improve that point =).

Depending on the size of your code base, it might also make sense to roll your own - writing one is not all that hard once you have a Java AST to work with given that the Java syntax is mostly a subset of C++, and there are many libraries which will parse Java code for you (j2c uses the one that comes with Eclipse for example). Doing a conversion by hand is a lot more error-prone than writing a tool for it.

like image 106
Jacek Sieka Avatar answered Nov 11 '22 17:11

Jacek Sieka