Portable programming in C/C++ ???

Posted 14 Feb 2003 at 09:09 UTC by Lehrig Share This

Portable !!! Not only Linux/Unix but also on OpenVMS, Mac, Windows ...

In principle I like to do portable programming. That is, your program not only runs on Linux/Unix but also on OpenVMS, Mac, Windows ... I mention OpenVMS because of my background. In scientific applications OpenVMS is still strong.

But how to do this ?

For the GUI I use qt http://www.trolltech.com . Although many people may argue that other really free GUI libraries are available, I have seen no library supporting all the mentioned OSs. With qt it is possible.

But what's with the low level functions ?

  • sockets
  • pipes
  • mailboxes
  • fifos
  • shared memory
  • threads
  • mutexes
  • semaphores
  • time
  • ini files

    Up to now I tried to wrap this functionality in a own library. If there already is a library for this purpose, please tell me.

    Would it be interesting, to setup a project for this purpose (eventually LGPL) ? Help welcome.

    I know, I didn't use STL, didn't use namespace, used printf() in C++ and all this bad things !!! May be I'am an old C-hacker, whom can't be helped at all. My idea, is NOT to discuss design or licensing issues. If someone is really interested in such a project, we can talk about.

  • Libraries, posted 14 Feb 2003 at 10:26 UTC by robocoder » (Journeyer)

    Differing in breadth, other notable attempts at portable libraries include:

    • ACE (The ADAPTIVE Communication Environment) - pattern oriented framework (see POSA2)
    • APR (The Apache Portable Runtime) - used by the Apache HTTP server
    • NSPR (The Netscape Portable Runtime) - used by the Mozilla browser

    There are already tons of projects out there, posted 14 Feb 2003 at 11:06 UTC by freetype » (Master)

    I know of two highly portable "support" libraries that include what you need:

    Both are fairly mature, and have been ported and tested on more platforms that you could shake a stick at. Really...

    There are also tons of other libraries that work well on a limited range of platforms (which generally means Windows + Unix), like:

    One big problem in my opinion with any large and highly portable projects is in their build systems. There are two common cases here:

    • there is one "big" Makefile for the developer's favorite platform and compilers. Since these are really atrocious things to write, they're generally generated with other tools like, *choke* Automake. These are maintained pretty frequently

      there are also a few "small" Makefiles or project files for specific platforms and compilers. However, they need to be updated "by hand" by volunteers, which is a pain in the ass. As a consequence, they're very rarely updated and the library is not correctly tested or even compiled on platforms that differ from the "favorite" one too much. And nobody's going to volunteer to port your library to something like OS/2 or Netware since rewriting the build control files from scratch is too hard.

      GLib is a good example of a very good general purpose library that is hard to compile on anything besides Unix and Windows, and that's not because of the sources, but the build system.

    • another common case is to design a specific build system, which is capable of handling all systems and compilers. Hence, there is a single set of control files describing the project. The problem being that most of these solutions are huge kludges based around legacy tools like "make", and that they're really hard to understand, maintain and upgrade to new systems. See "NSPR" and "XFree86" for detailed examples.

    There are many ways to avoid these two pitfalls, and all of them requires you to get rid of "make" for something that allows you to decribe your project in higher-level terms in control files while not being specific to a given project (e.g. Jam, Boost.Jam, Aegis which includes Cook and many others).

    I would suggest you to carefully choose your build system before anything else if you really want to write highly portable code. Otherwise, the chances that it will be easily ported to different architectures is ridiculously low, unless you've got a set of dedicated system experts who are ready to do the work for you consistently, which I doubt :-)

    Why not Qt (or TinyQ)?, posted 14 Feb 2003 at 13:15 UTC by tjansen » (Journeyer)

    Why not use Qt (or the TinyQ subset) for the low-level stuff as well? There is no need to use a second library.

    Right now Qt provides abstractions for TCP (QSocket), sockets in general (QSocketDevice), threads (QThread), mutexes (QMutex), time (QTime/QDate) and many other things (QNetworkProtocol, QFile, QXml*, QDom*, QLibrary...). You can also find many missing pieces, like ini files, in kdelibs. And at least I would be interested in having a KDE-like library that adds server-specific stuff to Qt, as I am already working on server code with Qt.

    Tcl (Python?), posted 14 Feb 2003 at 20:55 UTC by davidw » (Master)

    While not broken out into really useful libraries, I know that Tcl (maybe Python too?) has pretty good cross platform support in its C library. Might be worth a look, as it's also under a very liberal license.

    Portable GUI frameworks, posted 14 Feb 2003 at 22:52 UTC by atai » (Journeyer)

    There are many GUI frameworks that are as good as Qt in terms of portability. See


    for details.

    POSIX?, posted 14 Feb 2003 at 22:53 UTC by mrcsparker » (Journeyer)

    There are POSIX libs for all of the above platforms, including OpenVMS. As mentioned above, just use Qt.

    Why not use own library ?, posted 15 Feb 2003 at 09:06 UTC by Lehrig » (Apprentice)

    ACE looks good. Also Qt offers some portable functions.
    But since I have gone this far with my library I will stick to it for my own projects.
    I already have the functionality I want and I have full control over the library.
    In Qt for example, there are only posix calls, no SYS$ or LIB$* calls.
    This will limit the use of Qt at least under OpenVMS.
    But may be my idea is not good enough for a new project.
    I will just use it as a supplement for http://pvbrowser.sourceforge.net/

    Problem with your license statement, posted 15 Feb 2003 at 20:05 UTC by atai » (Journeyer)

    OK, you said you don't want license discussions. But you may still want to know this. Your license statements say that

     *   This program is free software; you can redistribute it and/or modify  *
     *   it under the terms of the GNU General Public License as published by  *
     *   the Free Software Foundation; either version 2 of the License, or     *
     *   (at your option) any later version.                                   *
     *                                                                         *
     *   I make one exception to the above statement:                          *
     *   You can use this software for commercial purposes                     *
     *   if you purchase a license                                             *
     *   You will not be allowed to make changes to the software               
    It is confusing. Maybe you should say "this sofware is licensed under the GNU General Public License..." (standard text)

    (For these people who cannot follow the GPL) Alternatively you can purchase the commercial license which allows modifications for use in proprietary software...

    No problem with license statement, posted 15 Feb 2003 at 20:30 UTC by Lehrig » (Apprentice)

    I said: eventually LGPL !!!

    Of course you found what you are showing. But that material should be a base for a discussion about the library. That license statement is obsolete.

    suprised no one has mentioned wxWindows, posted 21 Feb 2003 at 09:00 UTC by habes » (Journeyer)

    wxWindows seems to be exactly what you are looking for. It is provided under a free license, and supports all of the operating systems you mentioned (I don't know about OpenVMS though, you'd have to see).

    You get native widgets on platforms like Win32 (unlike Qt), and as far as utility functions it supports about half of your bullet points.

    The documentation is great and the project in general gives off an aura of being very thoughtfully designed and well implemented.

    New Advogato Features

    New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

    Keep up with the latest Advogato features by reading the Advogato status blog.

    If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!

    Share this page