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?"
many choices (Score:2, Interesting)
NSPR [mozilla.org], APR [apache.org], boost [boost.org] system, threads
TBB works wonders for threading (Score:5, Interesting)
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.
Re:Qt (Score:1, Interesting)
Remember one thing about LGPL. It requires that that user can replace the LGPL binary. So Qt released under LGPL must be a separate dll, no static linking.
Although, I cannot understand how iPhone and its apps get by this license requirement.
Re:Pthreads (Score:3, Interesting)
pthreads-win32 is excellent, but regrettably, LGPL licensed. It's interesting to note how complex it has to be to give you POSIX semantics [wustl.edu] --- pre-Vista win32 threading primitives are fundamentally flawed [msdn.com].
Vista, on the other hand, gives us brand-new innovative 21st-century Microsoft technologies like condition variables [microsoft.com].
Re:ACE is great! (Score:3, Interesting)
Qt has been modular since ver 4, so you don't have to include the GUI components if you don't want to. The API is clean, elegant and consistent, plus the documentation is great. I don't have anything bad to say about ACE or Boost - they're both high quality toolkits - but if I had to choose just one toolkit to use for the rest of my life, it'd be Qt, hands down.
You probably do not want ACE (Score:1, Interesting)
ACE introduced a lot of neat concepts into the mainstream as far as I/O goes (the Reactor pattern came from ACE) but it's really quite crufty and showing its age. It's probably the best thing there is for wrangling heavily-threaded apps, but you'll have to deal with threads more than you'll care for. You'll find the APIs in Boost and QT to be a lot nicer.
As for Berkeley DB, it's very nice, battle-tested, and perfectly suited for the type of task you're looking at.
Cygwin or UWIN (Score:5, Interesting)
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*
jdb2
Re:ACE is great! (Score:1, Interesting)
Avoid ACE, it is really poor. Have you every tried to compile and build it on modern systems? It just does not build. It looks like the project has been abandoned to me.
I tried to build it on 5 modern UNIX OSs recently and they all failed. The main reason is that the C++ code is poor written and C++ is not very portable because the C++ compilers only implement parts of the standard.
Re:JAVA (Score:4, Interesting)
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.
Re:Qt (Score:5, Interesting)
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.
Boost and sqlite (Score:4, Interesting)
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.
SQLite for database (Score:3, Interesting)
Another couple of options (Score:3, Interesting)
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.
Re:Sorry, C variants aren't trendy... (Score:2, Interesting)
C++ has a lot of properties, but "simple" is hardly one of them. It's got so much stuff munged into it that the spec contains literally hundreds of pages special-casing bad interactions between features, and it takes a gigantic effort just to determine the type of an expression. Parsing C++ is actually not only not context-free, but undecidable, in general. It takes a heroic effort to determine whether A f(B,C); is a function declaration, or a call to a constructor. Static resolution rules are horrifically complex. The interaction of templates with everything else in the language is riddled with pitfalls. Etc.
Re:Unfortunately probably not worth it (Score:2, Interesting)
I have long given up using the threading module in python itself, and have actually been using the Parallel Python module written by Vitalii Vanovschi extensively for my parallel processing needs. If you need multi-core / cluster processing and want to stick with python, this library is quite excellent. http://www.parallelpython.com
Re:Qt (Score:3, Interesting)
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:Boost? (Score:3, Interesting)
That's correct. Boost has the most stringent code review practices of probably any open source project.
This seems like an anti-open-source thing to do, but it's critical considering what Boost has to do. It's partly that library of infrastructure that all serious C++ projects need before they start, and partly the place where additions to the standard library are born. Boost development is slow, but Boost code is bulletproof.
Re:Sorry, C variants aren't trendy... (Score:3, Interesting)
C++ has a lot of properties, but "simple" is hardly one of them.
We use Qt at my job for creating servers, daemons, interacting with hardware as well as doing GUI stuff. You don't really need to use the fancy C++ stuff, it's OK to just use the Qt classes and be done with it. Our code almost looks like Java, so simple.