1

I have the following code snippet to accept runtime program options. Everything works well as long as I don't have --help on the command line. On invoking --help I receive

malloc: * error for object 0x7fff7b646570: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

on the boost::any::holder class. If the implicit_value setting is removed everything works well (even with --help). Am I missing something here?

TIA, Nikhil

// program options descritor
po::options_description allOpts("");
// general
po::options_description genOpt("General options");
genOpt.add_options()
("help", "produce help message")
;

// mandatory options
po::options_description manOpt("Mandatory options");
manOpt.add_options()
("tilesetData", po::value<std::string>()->required(),
 "tile set image file (required)")
;

// modifiables
po::options_description modifiers("Modifiable options");
modifiers.add_options()
("takeSnaps", po::value<std::string>()->implicit_value("gameShots"),
 "take screen shots after every display refresh")
("music", po::value<std::string>()->implicit_value("NOT_SPECIFIED.mp3"),
 "play the music specified by the file")
;

// compile all options
allOpts.add(genOpt).add(manOpt).add(modifiers);
// parse command line
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, allOpts), vm);

// create help message
if (vm.count("help")) {
    std::cout << allOpts << std::endl;;
    return false;
}



// check program options
try {
    po::notify(vm);
}

catch (std::exception& e){
    std::cerr << "Error: " << e.what() << std::endl;
    return false;
}
catch(...){
    std::cerr << "Unknown error!" << std::endl;
    return false;
}
Nikhil J Joshi
  • 1,177
  • 2
  • 12
  • 25

1 Answers1

0

I suspect this is due to an incompatibility between compiler versions. Probably the boost version you are using was compiled with an older version of gcc than the version you are using to compile the program. The solution is to use the same compiler to build boost and for compiling your program.

Jesse Good
  • 50,901
  • 14
  • 124
  • 166
  • I don't think compiler incompatibility is an issue. I am also seeing this error and in my case boost and my code are also compiled using same version of VS 2019. – munsingh Jul 30 '21 at 10:00