Making cpp code platform independant

Jul 4, 2013 at 5:28am
Hi everyone,
I have been working in java for some time. I am currently working on developing plugins for ETL tool in java. That ETL tool has been developed using C. I was just wondering there was no much use of java's oop concepts so why not use C++ instead? I asked my manager about this and he told me we use java because its platform independent. I just wanted to know if we can write a program in C++ and make it work on either platform? what changes do we need to make in the program? My apologies for such a generalized question, but using C++ in my project can boost up the performance of the plug-in, this is what I am thinking.
Jul 4, 2013 at 5:40am
AFAIK C++ by itself is a multi-platform language. However, the executable file that is created by the compiler is platform specific.

For instance, if C++ code is compiled in Linux, the executable generated shall work only on Linux OS and if the same code is compiled in Windows, then the executable shall work only with Windows.
Jul 4, 2013 at 5:47am
Certain libraries are also only available on certain platforms with C++. For example if you write code that utilizes WinAPI there is no way to compile a Linux executable because WinAPI is only available for Windows.

You can avoid that by strictly using crossplatform libs. But as abhishekm71 said... you still will have to recompile the program for every platform you want it to run on... whereas one java binary will run on anything with Java.

Java can get away with that because it runs through a VM (ie: the target machine has to actually have Java installed), whereas C++ compiles directly to a native program (there is no "C++" that the user has to install).
Jul 4, 2013 at 5:55am
ok so shall I say that C++ source code is portable but not the compiled code! Delivering source code to client and compiling it on his machine doesn't seem compelling option to me! Is 'java' only solution? Well I can find a way for that, but I just wanted to know how much performance gain can be achieved given code is properly optimized, over that of java?
Last edited on Jul 4, 2013 at 6:10am
Jul 4, 2013 at 6:09am
In reality there aren't too many different kinds of machines/OSes you need to support. I'd say (off the top of my head) the upper limit is around eight or nine. Many people won't bother to support more than Windows, Linux, and Mac.

I'm not sure I understand your problem though. Are you trying to develop plugins for your ETL tool using Java?

If the ETL was written in C, why not simply use C or C++ to target the same systems the ETL tool does?
Jul 4, 2013 at 6:42am
Well I am currently developing plug-in for tool in java. Vendor provides API for both, java and C++. So I am thinking of using C++ instead of java because I feel plug-in developed in C++ can perform faster than that of java(correct me here if needed). And platform independency is my concern.
Jul 4, 2013 at 7:02am
Ah, well. Unless you have some benchmarks saying Java will be too slow, just use the Java and save yourself some grief.

Sorry.
Jul 4, 2013 at 7:27am
Yes indeed I need to do more study on the performance difference and shall think of C++ only if it provides significant performance increment over java. I shall try getting more knowledge about this and hope to ask more specific questions next time,
thank you abhishekm71, Duoas and Disch for your valuable help..
Topic archived. No new replies allowed.