views:

962

answers:

3

I have a couple of hobby C programming projects that I would like to start. I am looking for an open source library that has a liberal license (I want credit, but pretty much anybody can use). The library needs to have strings better than the C standard library and some portable threading primitives.

I am considering GLib and APR. What is your practical experience? Which is the better foundational C library? Are there any other libraries filling the same niche?

+4  A: 

I'd go with APR. APR is better at portability Unix/Windows (being a dedicated portability library), GLib has traditionally been more Unix-oriented. APR is a larger library than GLib, with lots of useful stuff in it (hash tables, argument parsing, file I/O stuff, memory management, shared memory routines, signal handling, etc.).

JesperE
+6  A: 

Sorry, I think it's the other way round. glib has many more datastructures as portable libraries. e.g hash tables, all kind of lists, queues, stacks, dynamic array, also for argument parsing, file io has it's own wrappers also and memory managment is easy modifiable. E.g you can easily make glib use the Boehm Weisser GC this is AFAIKT never been done or easy possible with Apache. I would decide a bit different. If you need a more useful library of data structures glib is a better equipped. If it comes to GUI stuff than libapr has nothing whereas glib has gdk/gtk+ and a lot of stuff for gnome if you like.

Howerver if it comes to network stuff libapr has definitly an edge over glib.

So my suggestions is 1) Desktop programming (use GTK+ and glib 2) Network stuff (use apr, but be assured glib does has all this portable stuff also)

One can easily find out, reading through the docs

Regards Friedrich

Friedrich
+1  A: 

Is there a reason you wouldn't want to use the c++ stl? Even if you are writing "c-style" code without classes, you can use c++ strings and data structure.

There are plenty of valid reasons to stick to C, of course. If that's the case, I would second the recommendation for glib. APR is more of a portability layer than a utility library.

Speaking of C++ strings, I would recommend you reading what Linus has to say about this: http://thread.gmane.org/gmane.comp.version-control.git/57918
Cristian Ciupitu
Yeah, I agree Linus made the right choice to use straight C for git. Use whatever is appropriate for your project and target developer audience. C++ strings are nice, especially for a "hobby" programmer like the poster stated, because you don't have to track ownership and figure out when to free() them, and the auto-growing makes it so you don't have to worry about tricky strcat cases. Of course, as I said, "There are plenty of valid reasons to stick to C..." as well. Use what works for you.