File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes C / C++ and the fly likes How applications written in native languages are made cross platform Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » C / C++
Bookmark "How applications written in native languages are made cross platform" Watch "How applications written in native languages are made cross platform" New topic
Author

How applications written in native languages are made cross platform

Sanjeev Charla
Ranch Hand

Joined: Apr 02, 2009
Posts: 90

Applications like Firefox, VLC player . . .etc etc are available for mostly all types of OS. But they are implemented in platform dependent languages like c, c++.
Are they compile the source code for each and every OS by using related IDEs with platform dependent packages separately??
There are so many compilers like VC++, GCC . . .
Suppose i want to develop an application with c or c++, and i want to available that application for maximum OSs,
1. What is the procedure to select an IDE and tools for developing a software like this ??
2. what concepts i have to consider?

These are not my questions while i am in Java. .

Please explain in detail.
Anthony Aj Williams
author
Ranch Hand

Joined: Jun 10, 2011
Posts: 57
Sanjeev Charla wrote:Applications like Firefox, VLC player . . .etc etc are available for mostly all types of OS. But they are implemented in platform dependent languages like c, c++.
Are they compile the source code for each and every OS by using related IDEs with platform dependent packages separately??


Yes, the application is compiled separately for each platform, otherwise it won't work. This is why you see Linux downloads, Mac downloads and Windows downloads as separate entities.

Sanjeev Charla wrote:There are so many compilers like VC++, GCC . . .
Suppose i want to develop an application with c or c++, and i want to available that application for maximum OSs,
1. What is the procedure to select an IDE and tools for developing a software like this ??
2. what concepts i have to consider?


1. You can either stick to using a compiler that is available for all your targets, such as gcc, or you can choose a separate compiler for each target. The choice of IDE is entirely independent; choose something that you like to work in, whether that's Eclipse, Emacs, the MSVC IDE or something else. Then set up build scripts for each target.

You then need to choose libraries which are available across all your target platforms, or you have to write your own wrappers around the facilities available on each platform, so that your main code does not have to care. For example, you might choose to use wxwindows or QT for your GUI rather than MFC, since they are available on multiple platforms.

2. Generally, it is the OS APIs that differ, rather than the basic capabilities, though you might need to watch out for things like "long" being 64-bit on some platforms and 32-bit on others. Use libraries to hide the OS differences.


Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/
just::thread C++11 thread library http://www.stdthread.co.uk
Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
As an example, GCC has backends that can emit native code for many platforms: http://gcc.gnu.org/backends.html


Ping & DNS - my free Android networking tools app
Sanjeev Charla
Ranch Hand

Joined: Apr 02, 2009
Posts: 90

Thanks for your valuable responses . . .
Brian Overland
author
Ranch Hand

Joined: Sep 09, 2011
Posts: 36
Anthony AJ is completely right and has basically said it all.

I will add that C was designed from the start to be as platform independent as possible, which was a somewhat paradoxical goal given that it also enabled people to write "closer to the hardware." So, depending on how you wrote your code, you could write your programs to be as platform indendent... or platform DEPENDENT... as you wanted.

And C++ inherits most of C's traits, particularly with regard to data types...

Certain things in C (still in C++) are potential land mines. Particularly bad is the fact that "int" type is usually 16 bits wide on 16-bit systems, while it is 32 bits wide on 32-bit systems. This means that code running perfrectly well on 32-bit systems can "break" badly after being recompiled for 16 bit systems!

Someday we will even have 64-bit systems, and then the "int" type will be promoted to what is currently available as the "long long int" type -- usually 64 bits.

Consequently, you might want to avoid "int" type altogether and stick to "short" "long" and "long long int"... but even with those, be careful, because C++ spec does not absoltuely guarantee specific sizes. Oops! (Top secret advice: if you want to do what Microsoft and other companies do, define types such as "INT32" and "INT16" in header files, which you then carefully maintain for different platforms.... then use INT16, INT32, and INT64 as your primitive types. Avoid the standard types. That's if you want to be REALLY careful.)


My strong advice to you -- if you cannot avoid platform specific code -- is to "modularize" your program as much as possible (object orientation can sometimes help there, by the way) so that all the platform specific stuff (your I/O functions for example) is handled by just a few functions or classes. Then, write the rest of your program to be as platform independent as possible, so that you don't need to rewrite everything when you compile for a new system. Keep everything platform-dependent in just one module which you can rewrite as you need to.


Of course, you absolutely have to recompile for each new environment or platform! Each platform will have its own compiler or compilers created for it. In each case, the compiler's function is to translate the (relatively) more generic C++ code into machine code for that will run on that particular platform... and by "platform," remember, I refer to a particular processor type (thus different machine code), system architecture, and operating system.

Hope this helps,


== Brian Overland
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How applications written in native languages are made cross platform