Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
Programming Windows Technology

Platform Independent C++ OS Library? 310

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?"
This discussion has been archived. No new comments can be posted.

Platform Independent C++ OS Library?

Comments Filter:
  • Boost? (Score:3, Informative)

    by piojo ( 995934 ) on Sunday October 11, 2009 @03:26PM (#29712595)

    I know Boost has threading support, but I'm not sure how much. Have you looked at that? (It also has a bunch of other useful libraries, perhaps Filesystem being pretty useful for cross-platform work.)

  • Qt (Score:5, Informative)

    by Anonymous Coward on Sunday October 11, 2009 @03:27PM (#29712599)

    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).

  • Pthreads (Score:3, Informative)

    by SoftwareArtist ( 1472499 ) on Sunday October 11, 2009 @03:30PM (#29712613)
    I've used Pthreads successfully as a cross-platform threading library. http://sourceware.org/pthreads-win32 [sourceware.org] is a quite good implementation for Windows, and it's built into Linux (and all other POSIX compatible OS's, such as OS X, as well).
  • Re:Qt (Score:1, Informative)

    by Anonymous Coward on Sunday October 11, 2009 @03:30PM (#29712615)

    I agree. I was responsible for maintaining a cross platform application (Windows, Linux, and MacOS) and it was built on Qt. Why the OP did not simply do a google search on the subject confounds me. Cross platform UI tools have been around for as long as there have been 2 or more UI platforms.

  • Qt or GLib (Score:3, Informative)

    by ciroknight ( 601098 ) on Sunday October 11, 2009 @03:32PM (#29712623)
    Qt's "Core" library is a pretty solid platform shim. Plain GLib is also (somewhat easier to port due to no C++ ABI differences, but no native C++ api makes it less attractive to you).

    Either one is an exceptional choice.
  • Boost (Score:5, Informative)

    by aePrime ( 469226 ) on Sunday October 11, 2009 @03:33PM (#29712633)

    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.

  • Re:Boost? (Score:5, Informative)

    by Homburg ( 213427 ) on Sunday October 11, 2009 @03:34PM (#29712645) Homepage

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

  • Re:Qt (Score:5, Informative)

    by KirstuNael ( 467915 ) on Sunday October 11, 2009 @03:35PM (#29712647)

    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.

  • Re:Qt (Score:2, Informative)

    by d235j ( 1434583 ) on Sunday October 11, 2009 @03:39PM (#29712671)
    Simple: They post source code at opensource.apple.com and since they keep away from LGPL 3, they can use signing to, in effect, do "tivoization." And the iPhone and apps have dynamically linked libraries.
  • by QuoteMstr ( 55051 ) <dan.colascione@gmail.com> on Sunday October 11, 2009 @03:43PM (#29712689)
    I'm working on a rather large cross-platform C++ project at the moment. Here are a few tips:
    1. Use Boost [boost.org]. 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 [nongnu.org] 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.
  • Re:Qt (Score:1, Informative)

    by Anonymous Coward on Sunday October 11, 2009 @03:45PM (#29712703)

    I hate replying to myself, but forgot one thing:

    If you want to know what Qt has to offer without downloading it, you can check out their documentation online:
    http://doc.trolltech.com/4.5/

    Take a look at the list of classes as well.
    Don't worry, you can disable the modules you don't need (including the GUI) to reduce the overhead.

  • by boilednut ( 1245008 ) * on Sunday October 11, 2009 @03:47PM (#29712721)
  • Re:Qt (Score:2, Informative)

    by HeronBlademaster ( 1079477 ) <heron@xnapid.com> on Sunday October 11, 2009 @03:48PM (#29712729) Homepage

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

    What I actually need is a platform independent lib covering Windows and Linux variants to handle sockets, IPC and threads abstractions

    I wrote my own little socket class in C++ that does the Windows/Linux abstraction for me; they're mostly the same anyway, unless you want to get into epoll and such. I had planned to write a similar class for threads, but the idea is not exactly appetizing. I'm told boost has a thread class that might do the trick.

  • Re:Qt (Score:4, Informative)

    by Anonymous Coward on Sunday October 11, 2009 @03:50PM (#29712735)

    Point for point:

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

  • Re:Qt (Score:2, Informative)

    by morgan_greywolf ( 835522 ) on Sunday October 11, 2009 @03:51PM (#29712739) Homepage Journal

    Or GTK. Or specifically, gtkmm. Recent builds of GTKmm and Glibmm include stuff for handling sockets (Gtk::Socket). threads (Gtk::Thread, Gtk::Mutex, etc.) and IPC (GTK::Plug). Don't forget the GIO stuff, too.

  • Re:Boost (Score:5, Informative)

    by mls ( 97121 ) on Sunday October 11, 2009 @03:51PM (#29712743)

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

  • Re:Qt (Score:5, Informative)

    by rtfa-troll ( 1340807 ) on Sunday October 11, 2009 @03:53PM (#29712753)

    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.

  • by boilednut ( 1245008 ) * on Sunday October 11, 2009 @03:56PM (#29712763)
    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

  • Re:Qt (Score:3, Informative)

    by Lord Kano ( 13027 ) on Sunday October 11, 2009 @03:57PM (#29712767) Homepage Journal

    It's LGPL (So it's free for commercial projects as well)

    I'm sorry to nitpick, but this is an important distinction. You can use GPL code in a commercial project. I don't think that there's any dispute that RHEL is a commercial product. LGPL allows you do use code in proprietary projects.

    LK

  • wxWidgets might work (Score:3, Informative)

    by Beached ( 52204 ) on Sunday October 11, 2009 @04:01PM (#29712785) Homepage

    wxWidgets (aka wxWindows) does windowing, sockets, thread. I am not sure about DB, but I think it does. I haven't used it for DB yet.

  • Zoolib at Source Force [sourceforge.net] under the MIT open source license. It has a flat file database format, exists for multiple platforms, has platform-independent thread and mutex classes, graphical user interface toolbox, thread-safe reference counted smart pointers, file access, TCP networking. You can ask the main developers Andy Green or Michael Crawford to port it to a new platform that isn't supported yet, but it supports all of the platforms listed on the source forge page.

    The Zoolib Cookbook can help you get started. [goingware.com]

    The flat file database support is designed in Zoolib so that you can email someone the database file and they can click on it and open it up as an email attachment.

  • by Wrath0fb0b ( 302444 ) on Sunday October 11, 2009 @04:23PM (#29712891)

    From the FAQ - http://www.threadingbuildingblocks.org/wiki/index.php?title=Licensing [threadingb...blocks.org]:

    TBB is available under the common OSS license GPL v2 with the libstdC++ Runtime Exception. This is the same license used for a variety of well-known OSS applications including MySQL, NetBeans, and the Linux kernel.

  • by cbhacking ( 979169 ) <been_out_cruisin ... minus herbivore> on Sunday October 11, 2009 @04:29PM (#29712923) Homepage Journal

    It's mostly because they aren't answering the OP's question, and aren't contributing any useful information to the discussion. Compare the posts above with the following:

    From what I've heard, one of the best cross-platform libraries for C++ is QT, (originally developed by Trolltech, now by Nokia). It's available either open source (LGPL) or commercially, and while best known for its UI toolkit also provides an extensive library of other functions. Wikipedia [wikipedia.org] has a long list of things it has been used for, and other information.

    On the other hand, if you're not too wedded to C++ specifically, Java, C#, or Python might be good alternatives. Syntax-wise, C# and Java are extremely similar to C++, and all three have extensive libraries (built in) that provide the functionality you're looking for. They're also cross-platform (with C# you'd need to stick with stuff Mono [hhtp] can do, but that's still pretty extensive) and you don't even need to re-compile. Speed-wise, both Java and C# are nearly as fast as native code for most applications today, as are certain Python run-time environments. If you need explicit memory management for something, you can even do that with C# (although at that point it may be better to stick with C++).

  • by Jester99 ( 23135 ) on Sunday October 11, 2009 @04:37PM (#29712985) Homepage

    You say that you're writing a lot of "C-like" embedded C++. Are you doing fully OOP style coding and using 'new' and 'delete'? Or are you mostly taking advantage of conveniences like namespaces, scoped variable declarations, etc?

    If your code is really more C-ish, you could take a look at the Apache Portable Runtime (http://apr.apache.org/). The APR is the library that Apache httpd is based on; they cover most system-level utilities (sockets, files, etc) you could need in a portable way. The APR is more 'C-like' in that a file descriptor is an opaque handle which you pass in to functions like apr_file_puts(), etc., rather than doing the C++ thing of file->puts()..

    But if you're ok with the syntax, it's Apache licensed (corporation friendly), well tested (httpd is pretty ubiquitous after all) and actively maintained.

  • by Profane MuthaFucka ( 574406 ) <busheatskok@gmail.com> on Sunday October 11, 2009 @04:44PM (#29713025) Homepage Journal

    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.

  • Re:Boost and POCO (Score:2, Informative)

    by Profane MuthaFucka ( 574406 ) <busheatskok@gmail.com> on Sunday October 11, 2009 @04:50PM (#29713059) Homepage Journal

    No, POCO is not very good. The documentation is poor, and it's buggy.

  • by PCM2 ( 4486 ) on Sunday October 11, 2009 @05:07PM (#29713225) Homepage

    You're quoting from the commercial license. TBB is quite explicitly dual-licensed. If you don't like the terms of the commercial license, you have the option to use it under the terms of the GPL v2.

  • by alexmin ( 938677 ) on Sunday October 11, 2009 @05:26PM (#29713357)

    The sole reason for POSIX subsystem in WIndows was to satisfy formal criteria in some US government specs. No one is using it to actually _code_, AFAIK.

  • UGH (Score:1, Informative)

    by Anonymous Coward on Sunday October 11, 2009 @05:29PM (#29713365)
    If you've been write multi-platform code using the preprocessor, you don't know what the hell you are doing. Don't blame the tools, learn how it's support to be done. Hint: define a proper build system that doesn't require any preprocessing.
  • Re:Qt (Score:1, Informative)

    by Anonymous Coward on Sunday October 11, 2009 @05:49PM (#29713505)

    LGPL allows you do use code in proprietary projects.

    No it doesn't, but it does allow you to link against it. There's a difference. If you wan't to use open source in a proprietary project then you'd have to go with something like the BSD license.

  • Re:Boost and POCO (Score:3, Informative)

    by gbjbaanb ( 229885 ) on Sunday October 11, 2009 @06:26PM (#29713771)

    agreed, I used POCO for its email classes, and while it worked its documentation was somewhat out of date or incomplete. Still, I could figure out what was needed. what I didn't like was their adherence to the 'one true OO way' of developing libraries, too much of an exception hierarchy just isn't good.

    I didn't try the other parts and am probably not likely to. If boost had some general purpose classes (instead of mostly algorithms and general purpose classes) then I wouldn't have even looked at Poco.

  • Poco is your answer (Score:1, Informative)

    by HedgeBoar ( 1432905 ) on Sunday October 11, 2009 @08:36PM (#29714471)
    Boost is a good point to start and a good academic tool for the purists. ACE is trying to be too much for too many platforms. For real world use I ended up with Poco http://pocoproject.org/ [pocoproject.org], very good performance, works flawless on Win/Linux platforms (base on my experience) and has an easy to use interface.
  • Re:Cygwin or UWIN (Score:4, Informative)

    by TheNetAvenger ( 624455 ) on Sunday October 11, 2009 @09:40PM (#29714779)

    If you want "close to the metal" POSIX API compatibility then there's Cygwin

    Ok, but this is borderline 1990s thinking or a bit insane...

    You would be better off telling the person to just use the SUA of NT and develop a full *nix OSS solution and ignore Win32. As this is effectively what you are getting with Cygwin, except the SUA of NT is a full BSD subsystem that DOES RUN AT METAL 'so to speak' and doesn't have all the horrible 'kludges' of Cygwin.

    I mean seriously, I think people forget that NT does a very good V5 and BSD Unix already, that is far beyond POSIX compliance and yes even beyond Cygwin crap.

    ----

    To give a good answer to the OP, it would help to know what they are doing a bit more, as just knowing if they ware writing GUI or non-GUI code makes a BIG difference in picking a common or easily portable library. Also performance, what kind of performance do they need? Depending on what they are doing I could recommended truly using the SUA or Java or *gasp* .NET via Mono or QT or a ton of other solutions that do work and work well. Hell they might be doing an application can should be shoved into something like Silverlight.

  • by Pseudonym ( 62607 ) on Sunday October 11, 2009 @10:19PM (#29714907)

    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.

    Agreed, but you left out one crucial reason: If you use Boost today, this maximises your chances that your code won't need very much porting to work with the C++ standard library of tomorrow.

    Use autoconf [...]

    I'd like to agree here, but IME autoconf and Boost.Build don't work so nicely together.

  • POCO project (Score:2, Informative)

    by jbb999 ( 758019 ) on Monday October 12, 2009 @06:23AM (#29716949)
    Definatly take a look at poco project http://pocoproject.org/ [pocoproject.org] It seems to covera lot of what you want
  • Re:Qt (Score:3, Informative)

    by TemporalBeing ( 803363 ) <bm_witness.yahoo@com> on Monday October 12, 2009 @02:44PM (#29722273) Homepage Journal

    Qt is okay for networking applications, but in my experience Boost has much, much better performance, not to mention better support for things like multicast without creating some hacks. Qt ends up using a lot of Qt specific classes internally to create buffers and network functions, so it ends up being slower than Boost which seems to act more as a wrapper than anything.

    But does Boost provide behind the scenes threading?

    One of the things I've noticed with Qt is that they went out of their way to make the best possible performance. There's a lot of Qt classes (such as QTcpSocket) that implement threading behind the scenes so the performance is really hard to impact your application with (not impossible but a lot harder).

    Additionally, while there are a lot of things you do need to use the Qt classes for, it's typically very easy to convert many of those classes to and from C++ STL. Nearly all classes that have an STL equivalent have a function to convert the class to that STL equivalent or to to be initialized by an STL equivalent.

    Furthermore, you can easily intermix Qt Signals/Slots with other Signal/Slots implementations - such as the version provided by Boost. If you use the standard terminology then Qt will gladly use the third party Signals/Slots mechanisms itself; otherwise, you can use a couple macros (Q_SLOTS, Q_SIGNALS) to specify that you always want these signals/slots to be run via the Qt Signals/Slots.

    Honestly, I can't say that any other API platform has so much provided and so many methods for working with language native and third party mechanisms.

    The only thing that took a little getting use to was: (i) using a lot of pointers without having to keep track of quite all of them since the Qt Object Meta-systems does a lot of the cleanup for you (so long as the QObject has been parented), and (ii) Signals/Slots across threads requires a special QThread class implementation that only has signals with an internal class instance that has the signals/slots you would normally expect. Otherwise, Qt is the most intuitive, well documented, platform agnostic, and high performing framework out there.

  • Try TnFOX (Score:2, Informative)

    by ned14 ( 1354671 ) on Monday October 12, 2009 @02:59PM (#29722495) Homepage
    I also come from an embedded background and I didn't find a C++ platform abstraction library to my liking (i.e. fun to use and giving the programmer maximum power and control), so I went off and wrote my own: http://www.nedprod.com/TnFOX/ [nedprod.com] (docs are at http://tnfox.sourceforge.net/TnFOX-svn/html/ [sourceforge.net]). You can build a noGUI version which leaves out all the GUI stuff which should provide what you want: it also has a type reflecting metaprogramming database adapter with a copy of SQLite3 thrown in for good measure, and it is very seriously fast and efficient unlike most GUI toolkits e.g. all the bottlenecks use assembler or intrinsics and there is ample stream computing support which uses metaprogramming to assemble vector instructions. One major difference from libraries such as ACE is that I deliberately made TnFOX as fun to program in as possible - I have made zero attempt to make it academically "proper" or "pure".
    Hence it does come with an unusual programming paradigm - I make heavy use of C++ metaprogramming constructs and C++ exception handling and pervasive multithreading. And almost no one else uses it which I take it to mean that its learning curve simply isn't worth it for most people which is fair enough. In the end, if you ever want someone else to be able to work on your project then you need to use a well established toolkit which has a significant programmer pool attached to it. And ease of finding programmers is vastly more important than a "right" or "proper" or even "good" programming paradigm - as the designers of Plan 9, BeOS and NeXT found out.
    If your project is something recreational, do give TnFOX a look. If it's for something ever destined for outside your personal fun time, go with Qt or wxWindows or any big free portability library.
    HTH,
    Niall

The Macintosh is Xerox technology at its best.

Working...