C ++ boost options always setting default value

I try my best to make the performance improvement program settings work correctly. I need to run my program from a terminal window (Linux) with an optional argument that takes a value. No matter what I did, it did not work; no matter what value I typed from the terminal, it just returned the default value. Also, if I did not include an option in my termina command, she returned with

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injec tor<std::logic_error> >' what(): character conversion failed Aborted (core dumped) 

So, I found a minimal example on the Internet to find out if it was something that I did wrong. Here is an example that I found that does the exact same thing that I need:

  #include <iostream> #include <boost/program_options.hpp> namespace po = boost::program_options; int main (int argc, char* argv[]) { po::options_description desc("Usage"); desc.add_options() ("robots", po::value<int>()->default_value(3), "How many robots do you want to send on a murderous rampage?"); po::variables_map opts; po::store(po::parse_command_line(argc, argv, desc), opts); try { po::notify(opts); } catch (std::exception& e) { std::cerr << "Error: " << e.what() << "\n"; return 1; } int nRobots = opts["robots"].as<int>(); // automatically assigns default when option not supplied by user!! std::cout << nRobots << " robots have begun the silicon revolution" << std::endl; return 0; } 

This does the same thing, but I'm starting to think that this is either a bug in Boost (I hardly guess), or something about my system that I don't like?

Can someone hint at what might be wrong, please? Thanks

0
source share
1 answer

I ran into the same problem, going from 1.58 to 1.61 .
My problem was that I linked the 1.61 boost header code with the old 1.58 shared libraries.

You might have installed a newer version of boost, but that doesn’t mean you are still not linking to the old boost libraries. Check your linker. Check system files.
A good test you can do in your program is to run it through gdb , minimize it and look at backtrace (bt). It will show the version numbers for the accelerated version. See if this is as expected.

If appropriate, I was on Ubuntu and built from source:

 sudo ./bootstrap.sh --prefix=/usr sudo ./b2 install threading=multi link=shared 

This caused my library files to be located in /usr/lib/libboost* .
However, my linker looked at /usr/lib/x86_64-linux-gnu/libboost* .

A simple cp -Pf on old files solved my problem.

0
source

Source: https://habr.com/ru/post/1242960/


All Articles