20

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?

Rodney Schuler
  • 2,158
  • 4
  • 23
  • 34

3 Answers3

13

I think glib is generally superior to apr. 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.

However, if it comes to network stuff, libapr definitely has an edge over glib.

So my suggestions is

  • Desktop programming: Use GTK+ and glib.
  • Network stuff: Use apr, but be assured glib does have all this portable stuff also.
Friedrich
  • 5,916
  • 25
  • 45
7

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
  • 63,317
  • 21
  • 138
  • 197
1

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.

joeld
  • 31,046
  • 3
  • 27
  • 22
  • 1
    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 Aug 17 '09 at 18:52
  • 1
    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. – joeld Aug 28 '09 at 00:16
  • 1
    The question was specifically about coding in C, so the C++ STL is not relevant. (Yes I know this comment is 5 years after the fact. Boy, these Q&As sure do last, don't they?) – einpoklum Dec 21 '13 at 21:07