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?"
This platform independent lib you are looking for is called JAVA.
Nokia QT rocks...
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.)
A cat can't teach a dog to bark.
NSPR, APR, boost system, threads
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).
I've used Pthreads successfully as a cross-platform threading library. http://sourceware.org/pthreads-win32 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).
"I'm too busy to research this and form an educated opinion, but I do have time to tell everyone my uninformed opinion."
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.
"Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is." G.W.Bush
Intel Thread Building Blocks (http://www.threadingbuildingblocks.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 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.
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.
APR
Boost ( http://www.boost.org/ ) is good I also hear nice things about POCO http://pocoproject.org/
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.
---- aut viam inveniam aut faciam
As others have said BOOST is good. Also, I really didn't care for ACE and eventually gave up on it.
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.
http://www.nullsoft.com/free/jnetlib/ 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.
If you want "close to the metal" POSIX API compatibility then there's Cygwin which is easier to use IMO and more actively developed but doesn't support the *full* POSIX spec or there is UWIN which supports most of the POSIX spec.
;) or IMNSHO preferably wxWindows/wxWidgets and you've got yourself a full cross-platform programming toolkit that can do just about anything.
Combine this with OpenGL, OpenAL, the SDL and Cygwin/X, QT, a Java layer using the SWT from Eclipse, *shudder* GLUT *shudder*
jdb2
Zoolib at Source Force 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.
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.
Remember, Slashdot does not have a -1 disagree moderation, and no, troll, flamebait, and overrated are not substitutes.
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 the taping of my glasses, something geeky this way passes
#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.
yeah, Qt is made for C++ (despite there are plugins for Java and Python)
Everyone - Use this mish-mash of open source libraries and/or reinvent the wheel when you have to with interfaces and separate code files for OS specifics.
You don't need "mish mash" if libs if you use Qt.
Get with the program. Java isn't "special" anymore.
Save your wrists today - switch to Dvorak
boost::asio for networking + events, boost::treads for threading, and boost::interprocess for shared memory & other stuff...
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 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 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++).
There's no place I could be, since I've found Serenity...
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.
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.
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.
Got yer polarity wrong. He's the oldster, you are the whippersnapper. You should be saying, "I'll get off YOUR lawn". Otherwise, your advice is sound.
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!
SQLite dominates discussions of embedded databases these days, but Berkeley DB still has fans who don't need SQL. There are a lot of comparisons on the web.
*ducks*
Duh, Qt!
Did you just suggest emulating embedded hardware using python?
# cat
Damn, my RAM is full of llamas.
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.
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.
Java uses native thread exclusively. Anything you can do in C++ with threads, you can do faster and safer in Java.
Python has no ability to uses threads in a practical sense, due to Python GIL.
Mod me down, my New Earth Global Warmingist friends!
Considering Eclipse is probably the most widely used IDE in the world, do you have anything to back up your claims?
Mod me down, my New Earth Global Warmingist friends!
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.
"Embedded hardware" can mean anything--Python may be fast enough. And if it isn't, you can still write an emulation library in C and everything else (I/O, parsing, user interface) in Python.
hey, I still remember the wxCanvas stuff. this is really oldschool, apart from the fact that I'am GUI-less.
thanks anyhow, wx was cool last time I used it! (1994?)
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.
...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...
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
GP was being sarcastic?
And maybe a little (more than a little?) critical of AJAX, et. al.?
Maybe?
Computer memory is just fancy paper, CPUs just fancy pens with fancy erasers; the 'net is just a fancy backyard fence.
You beat me to the suggestion.
SQLite is a very powerful SQL database engine that is highly powerful and comes in a single < 500K library. No server needed.
Interfaces to it exist for most modern languages.
Documentation for the C/C++ API is here
A more C++ friendly wrapper for SQLite is on CodeProject
Is that the name of some kind of portable library?
Computer memory is just fancy paper, CPUs just fancy pens with fancy erasers; the 'net is just a fancy backyard fence.
TFA - Whats the best hack for c++ to let it be cross platform?
Everyone - Use this mish-mash of open source libraries and/or reinvent the wheel when you have to with interfaces and separate code files for OS specifics.
Me - Use a language and SDK that is MADE FOR CROSS PLATFORM COMPATIBILITY. JAVA JAVA JAVA
JAVA has cross platform sockets
JAVA has cross platform threads
JAVA has cross platform gui
C++ has header files... F**K HEADER FILES
C++ has pointers to pointers... F**K MEMORY MANAGEMENT
C++ makes you feel smart when you get something to actually work correctly... F**K YOUR EGO
+1
(disclaimer: I'm the author of this lib). LibNUI supports iPhone, Win32, Win64, MacOSX and Linux. It offers complete OS abstraction for Threads, Windowing, Unicode Strings, OpenGL / GLES / Direct3D GUIs and many widgets. You can use it in any GPL application or buy a commercial license. Check it out: http://libnui.net/
yeah, it's only part of the leading smartphone stack (Android, J2ME, etc), a large number of the top 10-20 most popular apps on sourceforge, runs most of the world's largest enterprise applications and runs most of the big software IDEs.
It's all hype! Yeah, Java!
Mod me down, my New Earth Global Warmingist friends!
In newer versions of OpenJDK this is not true.
Although in current use (java 6 et al), you're correct.
Mod me down, my New Earth Global Warmingist friends!
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/, very good performance, works flawless on Win/Linux platforms (base on my experience) and has an easy to use interface.
dito.
-><- no
There is a very stable C++ IDE in Ultimate++.
Quoting from the site:
"U++ is a C++ cross-platform rapid application development framework focused on programmers productivity. It includes a set of libraries (GUI, SQL, etc..), and an integrated development environment.
...
TheIDE can work with GCC, MinGW and Visual C++ 9.0 as contained in free Windows Vista SDK and contains a full featured debugger. TheIDE can also be used to develop non-U++ applications."
time time everywhere and not a second to spare
Apache Portable Runtime
Netscape Portable Runtime
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?
How about a platform-independent programming language complete with systems programming features, garbage collection, object-inheritance, type-safety and a way to bypass it when necessary? Have a look at Modula 3 and its libraries: http://en.wikipedia.org/wiki/Modula-3
Obviously there are not a lot experienced embed heads reading slash. Java:( If you don't like ifdef this or that try Java. Instead of ifdef, Java programmers us xml in what I call program by configuration file. It adds an entirely new dimension to programming that most skilled programmers would never have thought of. It is even more delightful when they use multiple overrides on their configurations files and you have to hunt through multiple files to to see how things are configured. Not only that, they can actually change the way code executes with configuration files. So not only do you have to look at code to see execution paths, you have to dig through multiple configuration files. It is truly the strangest methodology I have ever encountered. Stick with a C or C++ library. QT works well. For key value searchers Berkeley has no peer but SQLite works ell if you are into SQL.
wxWidgets emLib http://larytet.sourceforge.net/ are two options I used. emLib is available in LGPL - contact the author.
If you need a graphical user interface in your application go for Qt. Seriously, you won't regret it. I'm also using several other open source libs like Boost, but those won't help a bit to get your cross-platform GUI running. Qt, in contrast, handles that great, and has IPC, SQLite integration and thread abstractions a bonus. Besides, if you are starting as a "fresh" user , you will have benefit that once you have learned a bit Qt you will be comfortable with the other classes in the library as well. In contrast, if you decide to go for different lib for each purpose, you will have a lot more to learn (and to integrate).
I've used ACE a lot, 10 years ago, even then the code looked like it'd been hacked on by 4 generations of under-grads (which it had). Basic stuff works good, but there are some lurking race conditions in shared memory pools that you don't want to meet. I recommend Poco, industrial, easy-to-use etc.
http://pocoproject.org/
I wouldn't consider boost, yet, they're just starting to put in a full suite of cross-platform stuff and they're still missing some important pieces.
Boost is an absolutely incredible library, and any C++ programmer who doesn't use it is probably missing out. That being said, if you know ACE (i.e. have made it past the pretty steep learning curve) then ACE gives you more options. Boost's thread library is pretty great, but they simply don't have as fine control over primitives. There are also many things that you can do in ACE that you simply can't do in boost easily -- such as non-static pooled allocators.
Unless I am completely missing something, there is also no equivalent to the TAO in Boost.
I work on performance critical C++ code (yes, there really is such a thing) and we pretty much use ACE for anything involving IPC, sockets, or Threading -- and boost for everything else. That being said, the boost ASIO, thread, IPC, and Intrusive libraries are so easy to use compared to their ACE counterparts that unless performance is critical or boost simply isn't enough -- there isn't much use in learning ACE from scratch.
Try POCO. I've found it to be pretty useful.
And it has zlib license, so you can do anything with it.
Disclaimer: I have nothing to do with the library development, just a user.
Java, or link to the Cygwin library. The latter gives you a kind of POSIX API wrapper for your windows applications. So you can use POSIX threads and IPC stuff if you want. I'm not sure how efficient that is though, or how stable the general Cygwin API is.
Qt and SQLite. Seriously. LGPL and kick-ass! Also, Qt can be compiled to have SQLite completely built-in. No extra libs/dlls needed. It handles networking, threading, IPC, SQL and much more. No need for platform-specific ifdefs.
My other account has a 3-digit UID.
For really early adopters, C++0x includes built in threading support. You'll still have to use libs for sockets though.
The obvious answer would be QT, imho.
Definatly take a look at poco project http://pocoproject.org/ It seems to covera lot of what you want
I think modding people Troll is the /. equivalent of smacking dogs on the nose with a rolled up newspaper when they defecate in the apartment. I.e. it's just a way to stop them doing it again. Clearly no one wants to read "Why not use Java?!" in these sorts of discussions. Now you can't explain to a dog why indoor defecation is bad, just like you can't explain to Java programmers why Java is just a bad idea. Still shit in the apartment and posts advocating Java is not something which you need to tolerate.
echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
Have you heard of Hadoop?
Glib + Gtk++ is pretty decent. You also have Gnome Db for database access. A number of people have suggested QT and also WxWidgets. Both are pretty good.
the C++ GTK+ interface is great...deploying GUIs is really easy, swing/awt like...
Plus you have very good STL support and a lot threading/files/io cross platform support.
And it's proper C++!
Cheers,
So yes. Here's just a quick +1 on Boost and Qt.
Jag pratar lite svenska.
If you want what looks like a promissing web interface you might try http://www.webtoolkit.eu/wt. Life's beautiful when you can do web stuff in just one language
-- Many men would appreciate a woman's mind more if they could fondle it
Or maybe not, Qt, Boost seem good choices based on your experience, but it really depends. The best hw emulators (and simulators) I have seen / done / supported were written in LISP, yes, not new nor trendy.
And there is of course Erlang, it has all in language, is natively threaded even between nodes if desired, has very good database(s) natively, and so on - but not new nor trendy. Much less coding, configuration, etc effort than in most languages but maybe needs some time to get used.
I've rarely, if ever, seen a clear advantage of using forking. Using private structures per thread easily accomplishes the same task as forking and is highly portable. The one great forking advantage (crash resiliency) can still be accomplished by starting multiple processes from a script.
For most projects I simply use a startup script or threading. Another project I've enjoyed using is OpenMP - which can automate across machines and has great run-time controls and basic messaging.
I said no... but I missed and it came out yes.
I once killed a man right at his keyboard for claiming a segfault in the QT library. This is serious stuff.
Fascism trolls keeping me up every night. When I starts a preachin', he HITS ME WITH HIS REICH!
As an addition to the already mentioned, there is also a commercial grade that might be easier to use than Boost. SourcePro C++, you can check it out at http://www.roguewave.com/products/sourcepro/.
You say you're "emulating embedded hardware on Windows". What will you use the platform independence for? If you don't need it right now but "maybe in the future", I suggest skipping it. Write for Windows, but make sure ask the compiler to accept ISO C++ only, and don't sprinkle Windows-specific crud (UWORD, __declspec and whatever they are called) in the parts of the code which *are* platform-independent.
An unused portability layer only weakens your code.
Personally, I couldn't care less for Windows, so I develop under Linux and target Unix in general (not actively, but I expect it to be easy to port to some other decent Unix if I have reason to in the future). It's great -- I can use select(2), fork(2) and treat file descriptors and sockets alike. And I can learn from good books (e.g. Stevens) and discuss it with people who have been using those interfaces since, well, forever. No portability layers have that much support.
By the way, I don't see why you need a bloody *database* (even a nice one like BerkleyDB) to emulate flash memory. Can't you just mmap() a file?
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/ (docs are at http://tnfox.sourceforge.net/TnFOX-svn/html/). 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
In general, you'll be better off asking such questions on StackOverflow - you'll get an answer within minutes without having to wait for it to be posted. In fact, you wouldn't even have to ask - this is one of those question that's asked so frequently that there are plenty answers on various aspects of it.
The short answer is: if you need UI and/or are familiar with Java, use Qt. If you don't need UI or you really like idiomatic C++ (think STL), use Boost.
Microsoft Visual Studio's C++ compiler has an option that lets you generate 100% CLR binaries that will run on Mac and Linux with mono. The limitation is that you can only use the .Net API.
No, I will not work for your startup