Search code examples
c++clinuxboostgetopt

which library to use to parse command line arguments in C++


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.


Solution

  • 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.