9

I know about getopts and argp. I just looked in boost and they have program_options as a library for parsing command-line parameters.

I'm not exactly sure which one to use. I know getopts is POSIX, while argp isn't but that doesn't matter to me. What matters is ease of use. Can you recommend (pros/cons?) one. I'm open to other libraries too.

Anonymous
  • 18,162
  • 2
  • 41
  • 64
s5s
  • 11,159
  • 21
  • 74
  • 121

3 Answers3

14

If you want something lightweight and easy to use, then you might be interested in TCLAP (header only, liberal license). (example)

Otherwise boost::program_options (also liberal license) provides virtually anything one could need. (example)

Finally if you are already using a framework/library (WxWidgets, Qt) that has some command-line argument handling then probably the simplest option is to stick with that framework.

Community
  • 1
  • 1
Anonymous
  • 18,162
  • 2
  • 41
  • 64
2

You could also use popt.

If you are using a graphical toolkit like Gtk (thru GtkMM if in C++) or Qt, each of these offer their own command line arguments parsing facilities.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
1

glibmm has Glib::OptionContext. It's quite simple but does what most people need, in a standard way. It's not well documented, but here is an example that shows most of what it can do: http://git.gnome.org/browse/glibmm/tree/examples/options/main.cc

It wraps the GOptionContext C API in glib.

murrayc
  • 2,103
  • 4
  • 17
  • 32