I'm having some trouble using the program_options library.

Here is some code slightly modified from an example in the documentation for boost::program_options.


<code>
#include <iostream>
#include <vector>
#include <string>
#include <boost/program_options/positional_options.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/parsers.hpp>

namespace po = boost::program_options;

int main(int argc, char ** argv) {

  po::positional_options_description desc;
  desc.add("files", -1);
  std::cout << "Declared positional options." << std::endl;

  po::variables_map vm;
  po::store(po::command_line_parser(argc, argv).positional(desc).run(), vm);
  std::cout << "Stored command line arguments into vm." << std::endl;

  po::notify(vm);
  std::cout << "Notified vm that all args have been parsed" << std::endl;
  std::cout << "  num files specified: " << vm.count("files") << std::endl;

  std::vector<std::string> files = vm["files"].as<std::vector<std::string> >();
  for (unsigned int i = 0; i < files.size(); ++i) {
    std::cout << "file: " << files[i] << std::endl;
  }

  return 0;
}
</code>

Linking with version 1.40, the above code, when run with the command line arguments "hello world", produces the following output:

<shell>
Declared positional options.
terminate called after throwing an instance of 'boost::exception_detail::clone_\
impl<boost::exception_detail::error_info_injector<boost::program_options::unkno\
wn_option> >'
  what():  unknown option files
Aborted
</shell>

Linking with version 1.43, the above code, when run with the command line arguments "hello world", produces the following output:

<shell>
Declared positional options.
Segmentation fault
</shell>

Am I missing something about how to use positional arguments with this library?

I am using Ubuntu 10.04 on x86. The 1.40 version of boost::program_options was installed through the repositories, I compiled the 1.43 version manually.

Jeffrey