views:

1824

answers:

5

I'd like to use getopt in my C++ program, but the powers-that-be at my place don't want to use GPL or LGPL code (they're not that fond of Boost). Since getopt is licensed under the GPL (or is it the LGPL?), I can't use it.

Does anyone know of any alternatives?

A: 

Take a look at http://www.seebs.net/c/opts.html.

Ben Alpert
+8  A: 

Take a look at Boost.Program_options.

Dean Michael
Yeah program options is not bad.
Matt Joiner
+4  A: 

I'm pretty sure getopt is part of the GNU C Library, which is licensed under the LGPL, not the GPL, which means you can use it in your proprietary code as a library. You'll only have to give out the source code to libc, assuming you distribute it as part of your software package.

xyz
+2  A: 

There are many functions called getopt() and not all of them are licenced under the GPL. Once upon a long time ago (circa 1988, IIRC), an implementation of getopt() in C was released into the public domain by AT&T. It would need cleaning up and conversion to C++, but it would be free of the GPL.

It depends in part on what set of option characteristics you want to support. It is effectively the POSIX getopt(), supporting only single-letter options.

Jonathan Leffler
+1  A: 

NetBSD (and I'm sure other BSDs as well) has a BSD style licensed getopt (and getopt_long) implementation.

The NetBSD version is licensed under the 4-clause BSD license (the one with the advertising clause). Some people don't like that license as well.

Caotic