From C++ to Java
-
In which I attempt to swap to a more fashionable programming language, just as it becomes unfashionable: are there any good tools for translating C++ to Java? The objective: I have a large project in C++ that it's time to bring into the 21st century. Nothing clever about it, no tricky constructs, no pre-processor magic, just a big commandline app. I'm under no illusions that anything will be able to magically convert my code into a fully working program, but it would be good to have something to grind out boilerplate for the bulk of it, so that when I do the port I have at least something to use as a start and a structure to build around. The background: So why do I want to do the port? Multiple reasons - 1) This is the first stage in converting it to an app with a fully blown GUI. Sure, I could use go for one of the GUI libraries for C++ but see the next point. 2) I've ended up supplying this application (an evolutionary analysis package) it on multiple platforms, which has turned into a bit of a nightmare. My users largely can't use make files, so it really has to be pre-compiled before it gets to them. This has turned into a lot of maintenance effort, especially in the case of Windows which I don't use often at all. Fix a bug, build app on the Mac. Copy code to Linux box and build app there. Copy app back to Mac. Copy code to Windows box and build app there. Copy app back to Mac. Upload all three files. Get a new bug report ... It'd be nice to do one build and distribute just that. 3) There are some particular Java libraries for visualisation and output that I'm eager to use. 4) Having projects scattered across several languages (C, C++, Python, RealBasic, Perl, Java, Obj-C and more), I've decided to let some of the languages go fallow and shift what I can to Java and Python, due to the mental space they occupy and the strain of staying competent and up-to-date with multiple languages. And having to solve the same problem in multiple languages is all too common an occurence ("Hey, I could do this with that library I wrote in Python. Pity this program's in Realbasic ...") It could be argued that the effort in porting isn't worth the benefits. Indeed, that's what I have argued for the last few years but in my judgement that time has passed. Dragging the software across to Java will be a pain in the short term, but worth it in the long term. Results so far: * C2J: this gets mentioned a lot, but it's a bit flaky and works a file at a time. * Mocha and Cappucino: two academic projects that seem to be no longer available. * Jazillion: a commercial project with a good reputation and a "contact us for a quote!" price. Any other ideas? I stress again that I don't expect any magic bullet, but any rough conversion would be a help.
-
Answer:
I find it hard to believe a rewrite (in Java, sure, that's fine) wouldn't be desirable anyway. Couldn't you rewrite the thing into much, much better shape now that you're older and wiser? I've been involved in porting projects. Rewrites are always so much better.
outlier at Ask.Metafilter.Com Visit the source
Other answers
If you don't need to run on multiple platforms, you might look at the structure of your C++, start by porting the GUI to Java, and make http://en.wikipedia.org/wiki/Java_Native_Access calls to the C++ "guts" (logic) as you port over more of the logic. This might make your migration plans more manageable.
Blazecock Pileon
Rewrite. Cut and paste as needed.
jeffamaphone
I've never used it and I'd never advocate using such a tool in the real world but have you looked at http://nestedvm.ibex.org/? http://ovid.tigris.org/Ephedra/ might be worth taking a look at.
rdr
Another possible technique, if you're committed to Python, would be to try to build a sensible, OO-based Python API on top of your core C++ application code (which would maybe be a layer of thin high-level Python service objects on top of a middleware of low-level Python code that calls your C++ directly using http://docs.python.org/lib/module-ctypes.html). Once you have a high-level interface like that in place, you can start rewriting the core bits in Java, and replacing your ctypes middleware with straight jython->java calls. I guess you'd still be stuck with rewriting the entire thing at once, though, since you can't call ctypes from jython. You don't mention much about how your code is currently structured. If it's mostly procedural, C-style code with lots of function parameters and some C++ embellishments on top you'll probably have a more difficult time getting into idiomatic Java, in which case my own impulse would be just to rewrite it. If it's already very OO-oriented code you might have better luck with machine porting tools. I'm personally kind of skeptical about how useful they would be even if they worked extremely well, though.
whir
If it turns out to be too much of a pain, you can look at using wxWidgets for the GUI and cross compiling your C++ with mingw (http://wxdsgn.sourceforge.net/index.php provides a decent gui for this, even).
IronLizard
http://www.codeblocks.org/home also has multiple target support, IIRC.
IronLizard
Related Q & A:
- How to call java from c#?Best solution by Stack Overflow
- How to Convert a C++ Structure into C# Structure?Best solution by Stack Overflow
- How to Implement Gateway Service something similar to Oracle API gateway Using Java and Java based Open Source frameworks only?Best solution by Quora
- How to learn C# (moving from C++ to C#?Best solution by stackoverflow.com
- Difference between Java 2 and Java 6?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.