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.
3 Answers 3
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.
Comments
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.
Comments
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.