Slashdot Mirror


Platform Independent C++ OS Library?

quench writes "Hello! I have been away from Windows and Linux application software for 5 years or so, doing mainly C-like embedded C++ programming. Now, I am about to start a project emulating embedded hardware on Windows. Been there, doing #ifdef WIN32 and #ifdef LINUX stuff, don't really want to go there any more. What I actually need is a platform independent lib covering Windows and Linux variants to handle sockets, IPC and threads abstractions. And a rock solid but simple embedded database to emulate flash memory. My reflex said, go for ACE and Berkeley-DB. Tell me, am I out of time? Am I missing something new and trendy, easier to use and better? Did time stand still?"

10 of 310 comments (clear)

  1. Qt by Anonymous Coward · · Score: 5, Informative

    Use Qt. It's LGPL (So it's free for commercial projects as well), is well documented and offers a ton of abstractions (including sqlite).

    http://qt.nokia.com/

    And tool support is excellent as well (Visual Studio Add-In, Eclipse Plugin and a standalone IDE called QtCreator).

  2. Boost by aePrime · · Score: 4, Informative

    Boost has libraries for each of these three: sockets through the ASIO library, IPC through the Interprocess library, and threads through the threads library.

    http://www.boost.org

    The only thing that Boost is lacking for which you asked is a database library.

    1. Re:Boost by mls · · Score: 4, Informative

      SQLite databases are small, powerful and platform independent and might be a good choice to fit your database needs. The code is public domain.

      --
      -mls
  3. Re:Boost? by Homburg · · Score: 4, Informative

    Boost has pretty strong threading support, which is the basis for the threading capabilities in the forthcoming revision of the C++ standard. Boost also has cross-platform IPC and socket libraries. It would be a good choice for the OP, I think.

  4. Re:Qt by KirstuNael · · Score: 5, Informative

    I concur. My Qt-powered multithreaded and networked (TCP&UDP) application is compiling and working nicely in linux, osx and win32 without any os-specifc #ifdefs.

  5. As someone working on a massive project... by QuoteMstr · · Score: 4, Informative
    I'm working on a rather large cross-platform C++ project at the moment. Here are a few tips:
    1. Use Boost. It's a very liberally-licensed, high-quality library from the people who created the C++ language itself. It contains a ton of cross-platform libraries that do lots of useful things, from threads to regular expressions to writing testsuites and parsing command-line options. If Boost provides a piece of functionality, there's very little reason not to use its version.
    2. See rule #1.
    3. If you need cross-platform code that isn't in Boost, at least use the following approach:
      • Create a common interface definition
      • In separate files, implement the interface in terms of various platforms' primitives
      • Keep platform-specific code out of the rest of your program; if you can help it, don't even include platform headers in most of your program
    4. Use autoconf to handle platform idiosyncrasies. There are a ton of available macros to help detect things about a build platform.
    5. Write testcases. You should write tests for all your programs, but it's especially important to do it for cross-platform code because it's easy to break something and not notice.
  6. Re:Qt by Anonymous Coward · · Score: 4, Informative

    Point for point:

    - sockets
    - IPC
    - threads abstractions
    - Database. Well, not quite so simple, but Sqlite3 as backend is available.

  7. Re:Qt by rtfa-troll · · Score: 4, Informative

    OP didn't say anything about UI, as you'd surely know if you had bothered to read the summary:

    QtCore has more or less nothing to do with UI.

    --
    =~ s,(.*),<sarcasm>$1</sarcasm>,g if any_point_you_wish();
  8. Re:Apache Portable Runtime by boilednut · · Score: 5, Informative
    From the wikipedia articel:

    APR was originally a part of Apache HTTP Server, but has now been spun off into a separate project of the Apache Software Foundation, and is used by other applications to achieve platform independence. The range of platform-independent functionality provided by APR includes:
    * Memory allocation and memory pool functionality
    * Atomic operations
    * Dynamic library handling
    * File I/O
    * Command argument parsing
    * Locking
    * Hash tables and arrays
    * Mmap functionality
    * Network sockets and protocols
    * Thread, process and mutex functionality
    * Shared memory functionality
    * Time routines
    * User and group ID services

  9. Re:C++ is so old school... by Profane+MuthaFucka · · Score: 5, Informative

    Yes, QT is really excellent, but it's worth it to look at Boost as well.

    Want a database? Why use Berkeley when there's SQLite?

    Portable sockets? QT and Boost both have them.

    Portable file ops? QT and Boost both have them.

    Data structures? QT has a bunch, but STL is what you should learn.

    Windowing lib? QT works on both Windows and Linux. You may be tempted to use WXWidgets, but don't. Despite the fan boyz, you'll find that library to be buggy as shit, and impossible to debug. Sorry, that'll probably get me marked as a troll, but it's true.

    And QT on Windows comes WITH the MinGW compiler for Windows package. You don't need to use any other tool than gcc on Linux, Mac, or Windows.

    --
    Fascism trolls keeping me up every night. When I starts a preachin', he HITS ME WITH HIS REICH!