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:
  • JAVA (Score:3, Insightful)

    by Anonymous Coward on Sunday October 11, 2009 @02:23PM (#29712573)

    This platform independent lib you are looking for is called JAVA.

    • Re:JAVA (Score:4, Interesting)

      by HiThere ( 15173 ) <charleshixsn@NOsPam.earthlink.net> on Sunday October 11, 2009 @03:25PM (#29712903)

      That's not really a bad suggestion. Ruby, Python, even some dialects of Basic would work.

      Also consider Pascal. There are dialects of Pascal that have strongly attempted to be identical across platform boundaries.

      Additionally, anything that's running on a virtual machine would be a reasonable consideration. That includes qemu and xen, not just Java, Python, etc.

      What's at question are "What are the requirements??". Without knowing that, there's no way to know which, if any, of these suggestions are reasonable. Given that the initial language is C++, I'd expect that Pascal is the best replacement, with Java a close second. But if speed isn't a limiting factor than the other suggestions should be given consideration.

      Of course, what he's asking it probably more readily answered by something like FLTK, but it's hard to know, since we don't know exactly which features he needs to be handled by his library. FLTK is platform independent, and callable from C++, but pretty much only handles the graphic interface. If that's all he needs, then it's a good answer, but we don't know what his needs are.

  • Qt (Score:5, Insightful)

    by Anonymous Coward on Sunday October 11, 2009 @02:25PM (#29712587)

    Nokia QT rocks...

    • Re:Qt (Score:5, Informative)

      by KirstuNael ( 467915 ) on Sunday October 11, 2009 @02: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:3, Interesting)

        by Doppler00 ( 534739 ) on Sunday October 11, 2009 @06:12PM (#29714095) 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.

        • Re:Qt (Score:3, Informative)

          by TemporalBeing ( 803363 ) <{bm_witness} {at} {yahoo.com}> on Monday October 12, 2009 @01: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.

    • Re:Qt (Score:4, Informative)

      by Anonymous Coward on Sunday October 11, 2009 @02: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 @02: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:Qt (Score:5, Interesting)

        by jmv ( 93421 ) on Sunday October 11, 2009 @03:30PM (#29712941) Homepage

        I've once attempted to use Gtkmm for a new project. While the API is generally well designed, I found that the documentation for many features was totally inexistant. Even more annoying was the fact that some components were either buggy or not wrapped (from C Gtk) at all. Combined with the fact that components get created and deprecated at a huge rate, you don't even know what you should be using. Overall, I've had a really bad experience with Gtk (and especially gnome) development. I've only tried using Qt a little bit and so far I like it a lot. I've never done GUI with it though. I've used the "platform independent system library" part for things like threads, sockets and the like. The only thing I found a bit annoying was that it didn't integrate well with the STL.

        • by odourpreventer ( 898853 ) on Sunday October 11, 2009 @07:55PM (#29714557)

          > The only thing I found a bit annoying was that it didn't integrate well with the STL.

          Is there anything that does? Boost has some alternatives to STL classes, and I'm sure Qt has as well.

          STL has a nice API, but that's about it.

  • Boost? (Score:3, Informative)

    by piojo ( 995934 ) on Sunday October 11, 2009 @02: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.)

  • many choices (Score:2, Interesting)

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

    NSPR [mozilla.org], APR [apache.org], boost [boost.org] system, threads

  • Qt (Score:5, Informative)

    by Anonymous Coward on Sunday October 11, 2009 @02: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 @02: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).
  • Qt or GLib (Score:3, Informative)

    by ciroknight ( 601098 ) on Sunday October 11, 2009 @02: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.
  • by Wrath0fb0b ( 302444 ) on Sunday October 11, 2009 @02:32PM (#29712625)

    Intel Thread Building Blocks (http://www.threadingbuildingblocks.org/ [threadingb...blocks.org] is (are?) fantastic. Open source (GPL), works on any ISO-compliant C++ compiler and is fairly intuitive. It allows both high-level (parallel_for) and low level (task-based) parallelism. Particularly useful are the concurrent containers, since it saves you from reimplementing these basic structures.

  • Boost (Score:5, Informative)

    by aePrime ( 469226 ) on Sunday October 11, 2009 @02: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.

  • by Arakageeta ( 671142 ) on Sunday October 11, 2009 @02:42PM (#29712685)

    I've had great experiences with ACE. I found ACE to be dependable and extensive. You don't even have to use the higher level design patterns to get the platform independence.

    If you're targeting *only* Windows and Linux, then Qt may also be a good option. I'm not sure if you can strip out the GUI stuff if you don't need it.

  • by QuoteMstr ( 55051 ) <dan.colascione@gmail.com> on Sunday October 11, 2009 @02: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.
    • by Anonymous Coward on Sunday October 11, 2009 @02:52PM (#29712745)

      Use autoconf to handle platform idiosyncrasies.

      Ugh. Autoconf & automake are the most horrible things I've tried to use in recent times. These tools are far from simple and what works with newer versions of the tools isn't even compatible with older versions. The syntax is antiquated and there are multiple ways to achieve the same thing each with different pitfalls.

      Somewhere there is a meteorite set to strike autoconf. I hope it gets here soon since it's about 20 years late...

    • by Anonymous Coward on Sunday October 11, 2009 @02:57PM (#29712765)

      it is all well and good, but he cannot even read options 3,4 and 5 because of your recursion!

    • by Pseudonym ( 62607 ) on Sunday October 11, 2009 @09: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.

  • by Adam Hazzlebank ( 970369 ) on Sunday October 11, 2009 @02:58PM (#29712773)
    Boost ( http://www.boost.org/ [boost.org] ) is good I also hear nice things about POCO http://pocoproject.org/ [pocoproject.org]
  • wxWidgets might work (Score:3, Informative)

    by Beached ( 52204 ) on Sunday October 11, 2009 @03: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.

  • by sribe ( 304414 ) on Sunday October 11, 2009 @03:02PM (#29712789)

    As others have said BOOST is good. Also, I really didn't care for ACE and eventually gave up on it.

  • by darkain ( 749283 ) on Sunday October 11, 2009 @03:07PM (#29712817) Homepage
    http://www.nullsoft.com/free/jnetlib/ [nullsoft.com] From the guy who initially made Winamp, he also made a lib called JNetLib which is a piss easy to use cross-platform C++ socket library. It also has pre-made classes for things like HTTP/HTTPS, to help speed things up, or to simply give you an idea of how to use the library. It is licensed under the BSD license, so you are basically free to use it for whatever you would like, commercial or otherwise.
  • Cygwin or UWIN (Score:5, Interesting)

    by jdb2 ( 800046 ) * on Sunday October 11, 2009 @03:10PM (#29712831) Journal
    If you want "close to the metal" POSIX API compatibility then there's Cygwin [cygwin.com] which is easier to use IMO and more actively developed but doesn't support the *full* POSIX spec or there is UWIN [att.com] which supports most of the POSIX spec.

    Combine this with OpenGL [opengl.org], OpenAL [creativelabs.com], the SDL [libsdl.org] and Cygwin/X [cygwin.com], QT [nokia.com], a Java layer using the SWT [eclipse.org] from Eclipse, *shudder* GLUT [opengl.org] *shudder* ;) or IMNSHO preferably wxWindows/wxWidgets [wxwidgets.org] and you've got yourself a full cross-platform programming toolkit that can do just about anything.

    jdb2
    • by TrancePhreak ( 576593 ) on Sunday October 11, 2009 @04:27PM (#29713361)
      Cygwin does terrible things with its DLL and explodes in certain evironments.
    • by Doppler00 ( 534739 ) on Sunday October 11, 2009 @06:14PM (#29714111) Homepage Journal

      Cygwin is a huge pain. Yeah, it sort of gives you a POSIX environment, but good luck getting anything to actually compile under it without hours of frustration.

    • Re:Cygwin or UWIN (Score:4, Informative)

      by TheNetAvenger ( 624455 ) on Sunday October 11, 2009 @08: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.

  • 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 CptNerd ( 455084 ) <adiseker@lexonia.net> on Sunday October 11, 2009 @03:13PM (#29712849) Homepage
    Unfortunately all the trendy cool kids are using Java these days, and only web-based applications are worth working on if you want to keep up with the times. The days of small, simple client-server apps are over, old hat, out of date, archaic. Nowadays you need to implement a web application using AJAX, web services, Struts and Spring and Hibernate, and you have to do it using Agile methodology. If you aren't linking in at least 100 Java class libraries, you don't have a "real" application.

    C++? Too simple.
  • by tomhudson ( 43916 ) <barbara@hudson.barbara-hudson@com> on Sunday October 11, 2009 @03:14PM (#29712853) Journal

    #ifdef __BSD__

    BSD and linux are different in some aspects when it comes to sockets. Made it a real PITA to code on linux, runs perfectly, then won't compile on BSD without a few more includes and some extra code.

  • Just use POSIX (Score:2, Insightful)

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

    That handles all the things you mentioned, and you can compile pretty much all the same code natively on Linux or using Cygwin on Windows without having to bother with #ifdeffery at all.

  • Boost and sqlite (Score:4, Interesting)

    by rudedog ( 7339 ) <{dave} {at} {rudedog.org}> on Sunday October 11, 2009 @03:35PM (#29712963) Homepage

    For most cross-platform stuff, boost will do what you need. boost::thread will handle all of your threading needs.

    boost::filesystem for manipulating pathnames; boost::datetime for date and time operations; boost::format for typesafe printf style I/O.

    It also has boost::asio for sockets and boost::interprocess for IPC. I know nothing about them, but to judge from the quality of the rest of the boost library, they are probably very good.

    For database, use Sqlite. It's a solid relational database stored in a single file, and you can even access the database from the command line for ad-hoc queries/debugging/whatever.

  • by Jester99 ( 23135 ) on Sunday October 11, 2009 @03: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.

  • SQLite for database (Score:3, Interesting)

    by PizzaFace ( 593587 ) on Sunday October 11, 2009 @03:50PM (#29713061)
    SQLite [sqlite.org] dominates discussions of embedded databases these days, but Berkeley DB [oracle.com] still has fans who don't need SQL. There are a lot of comparisons on the web.
  • by Vahokif ( 1292866 ) on Sunday October 11, 2009 @04:06PM (#29713207)
    *ducks*
  • by solid_liq ( 720160 ) on Sunday October 11, 2009 @04:07PM (#29713231) Journal
    Duh, Qt!
  • by EvilIdler ( 21087 ) on Sunday October 11, 2009 @04:50PM (#29713513)

    There's always wxWidgets, which you can compile into your program if you feel like it. Quite liberal.
    It's not a mere library, but a full framework, like Qt. I find the wx runtime to be smaller than an equivalent Qt program most of the time, and the Mac version of Qt's dylib bundler sometimes makes some stupid decisions which bloat the app by 50MB. wxWidgets (statically linked) gives me a 1.7MB executable for a Hello World-ish program.

  • by RonBurk ( 543988 ) on Sunday October 11, 2009 @05:18PM (#29713725) Homepage Journal
    The Java repliers are right on the mark. Trying to use app-independent portability layers ensures apps of any complexity will suck. By "suck", I mean "compromised at every turn by lowest-common denominator design decisions". Your app will end up using threads on an O/S designed to make multi-processing beautiful (Linux), or end up using multiple processes on an O/S designed to make multi-threading beautiful (Windows). It'll be clueless about the nifty GUI features that exist on a Mac but not Windows, and vice versa. Knowing up front that your app is going to suck allows you to, in all good conscience, choose a language that highly adapted for creating apps that suck in this manner. When I fire up a Java app on Windows (and I ALWAYS know it's a Java app the minute it finally manages to lumber onto the screen), I know I'm going to get the same sucky behavior if I fire that app up on a totally different platform (well, assuming I can manage to figure out whatever obscure infinite-megabyte downloads are needed to get the right "runtime engine" for the given app). Really, the only way you can make your app suck even more and be even more portable is to just go ahead and make it a web "service". That has the added advantage that nobody really expects anything but poor performance and clunky UI design from the get-go. But if for some reason you can't have your app suck as bad as a web service, then Java is definitely the next-suckiest way to achieve that portability that your end users don't give a crap about, but you hope will make your life easier.
  • by taoboy ( 118003 ) on Sunday October 11, 2009 @05:50PM (#29713933)

    ...are ones with which I have the most experience. WxWidgets IMHO is the best 'close-to-the-metal' API, with the most available constructs to allow me to implement in C/C++ the Perl prototypes I develop. But most recently I've been noodling with Java to develop a high-availability platform, and I regularly run multiple jvms in Windows command shells to build stuff out, and then take the classes unchanged to a ttylinux-SunJRE-based cluster I run with VirtualBox.

    I'm not a Java advocate by any means, but you can't ignore the portability...

  • by Dahamma ( 304068 ) on Sunday October 11, 2009 @08:41PM (#29714781)

    And a rock solid but simple embedded database to emulate flash memory.

    This part I don't understand... flash is a hardware solution to persistant storage. An embedded database is a software solution to structured storage of data. The two are completely orthogonal.

    Ignoring the flash part, I have used sqlite on several embedded projects (set top boxes) and it has done the job. Depends on your requirements though - is the priority speed, space, ease of use/API, etc?

Tomorrow's computers some time next month. -- DEC

Working...