12

Is it bad form to use the GNU getopt in C++ programs? Is there a C++ specific alternative, or should I still just use getopt?

oadams
  • 3,019
  • 6
  • 30
  • 53
  • Not really a duplicate, but see: [getopt implementation suitable for proprietary C++ programs?](http://stackoverflow.com/questions/456797/getopt-implementation-suitable-for-proprietary-c-programs) for ideas. – Greg Hewgill Oct 24 '10 at 04:03

7 Answers7

9

There is nothing wrong with using getopt. There are a multitude of object oriented alternatives floating around including Boost.Program_options, and classes in POCO, and ACE.

Duck
  • 26,924
  • 5
  • 64
  • 92
5

In C++ you can also use boost::program_options.

codaddict
  • 445,704
  • 82
  • 492
  • 529
5

I don't know that there's anything wrong with using getopt. But you might want to look at Boost.Program_options.

Fred Larson
  • 60,987
  • 18
  • 112
  • 174
3

Not at all, getopt is perfectly fine in C++. The Boost::program_options require that the Boost library be installed, which many may not have.

greg
  • 4,843
  • 32
  • 47
  • Boost can be built as static libraries. Otherwise, you'd practically have to ship the dynamic libs with your project *anyway*. – greyfade Oct 24 '10 at 04:11
  • 1
    I mean that the "devel" packages for many Linux distros may not include Boost by default. – greg Oct 24 '10 at 12:07
2

I like TCLAP (http://tclap.sourceforge.net/) the Templatized C++ Command Line Parser Library.

Sebastian
  • 2,876
  • 2
  • 24
  • 28
2

Look at this: http://michael.dipperstein.com/optlist/index.html

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
2

Try CLPP library. It's simple and flexible library for command line parameters parsing. Header-only and cross-platform. Uses ISO C++ and Boost C++ libraries only. IMHO it is easier than Boost.Program_options.

Library: http://sourceforge.net/projects/clp-parser

26 October 2010 - new release 2.0rc. Many bugs fixed, full refactoring of the source code, documentation, examples and comments have been corrected.

Denis Shevchenko
  • 1,342
  • 2
  • 10
  • 23