Tuesday, December 20, 2011

openoffice u3How do I make an application portable?

Making a open source application portable, NOT U3, U3 doesn't work all the time. I'm talking about plain old binary. Stuff like FirefoxPortable, OpenOffice.Org Portable; not Opera@U3 or Skype for U3. I would like it to be detailed, if possible.
Run it through a compiler. That is what they do. Convert symbollic text (software code) into binary. The compiler you use all depends on the language you are programming in.

For example, for c/++, in linux you could use gcc/gpp to compile an application. It could then be ran standalone on other linux computers. Windows/Mac/all computers in the world work this way. Just FYI the most basic compiler is called an assembler, it takes symbollic assembly language (the most basic human readable computer code) and converts it directly to the hex equivelant, i.e. binary. Many high level languages like C convert to assembly before the final compilation into hex (binary).
I'll assume, given the phrasing of the question, that you're somewhat familiar with computer programming in general, but not experienced or trained enough to understand all the complexities of writing portable software. I'm also assuming you're using some variant of C, because that is the language that most people have trouble with in regard to portability.

C was designed to be portable, but it was also designed in a time before we had the kind of experience we do today. Also, C is designed to be fast, which I suspect necessarily makes it somewhat less portable. For example, many datatypes in C, such as the integer datatype, have a variable storage size. That is, on a 32 bit computer, 32 bits are used to store the variable. On a 64 bit computeropenoffice u3, 64 bits are used to store the variable.

This isn't a problem, unless you write a program on a 64 bit computer that stores a big integer, then turn around and test it on a 32 bit computer. Or, you make the sloppy mistake of figuring an array index by multiplying a number by 32 (or 64).

Also, libraries (especially GUI and threading libraries) vary from platform to platform. While the standard C library has a few inconsistencies between its implementations, threading and GUI libraries seldom make even superficial attempts at similarity. It's probably best that they don't, as it may encourage developers to do foolish things.

To get around issues such as variations in variable size, etc, I recommend using GNU's autoconf tool. Used properly, it analyzes your system and sets up a handful of header files for you. For thread programming, GNU's Portable Thread library may be of interest. Finally, for GUI programming, you may look into TrollTech's QT library. (For the record, QT is more than just a GUI library.)

You may also look into O'Reilly's "Writing Portable Code" by Brian Hook. If you don't need to write code in C, you may consider a higher level language just as Java or Python, because they are generally far easier to develop highly portable software with.

Hope this helps.
If your using graphics which most apps do today you need a graphics lib that is very portable. In that you are in luck. There are several such libs which make cross platform development quite easy. Which one to use depends on what you are doing. Each have advantages. If your not dealing with sound then one lib may be a better choice than another. Go to
openoffice u3
You will find several libs, mostly C/C++ which will help.

There are also languages that are OS independent. Java was designed as such. Java is a complex language and there are many issues with cross platform compatability. Gambas is very much like VB but will be cross platform soon. Right now it's pretty much Linux only for the GUI, but supports console apps on other platforms.

A third option is writing your app in something like Python or Perl which will give you nearly %100 platform independent code if your carefull about how you write it. Since the binary level stuff is done in the interpeter you do not have to worry about most compatability issues, it's taken care of in the interpeter. To prevent tampering you can put the code into objects and distribute those instead of the raw source. You give up a little execution speed doing this but gain a great deal of flexibility.

Borland and Code Warrior are comercial options for the same thing. Both support Linux and Windows in compiles and are likely to also support Mac OS X, especially Code Warrior which started on the Mac. Both offer IDEs which run on Linux, so that's a plus for development and debugging the core code. Both offer extensive GUI building widgets and WYSWYG kind of GUI functionality.

Key issues to watch is to not access hardware directly. Do it through OS layers. Another is to not use OS specific libs such as direct X or GTK. Instead you can use stuff like QT, SDL, Open GL which support most platforms.

Hope this helped.

No comments:

Post a Comment