Boost logo

Boost Users :

From: Tom Lenaerts (tlenaert_at_[hidden])
Date: 2008-05-18 05:05:49


Hi everyone,

I recently obtained a new Mackbook pro with Os X leopard on it. I installed the latest Boost library using Macports .
Yet when I take my previous projects (build on Os X tiger with Xcode 2.5 and Boost -1_34_1) I have problems with the programming_options library.

So I created a simple command line project (see main in the end of this mail) to track down the problem and found that Xcode is having problems with strings in the program options.
I'm writing Xcode because when I compile the same code from command line using g++ there are no problems at all. So it has to be somewhere in the specifications.

I'm pretty sure that I specified where to look for the header files and the libraries. I added the libprogram_options_mt-1_35.dylib as a framework
to the Xcode project. The code compiles in Release configuration but when I try to run it I get :

>>> ./test -R 1 -L 1 -A 20 -S data.in -O result.txt
terminate called after throwing an instance of 'boost::bad_any_cast'
  what(): boost::bad_any_cast: failed conversion using boost::any_cast
Abort trap

The problem arises as soon as the code starts to process the vector<string> arguments.

When I then try to compile the samen code in Debug model I get three errors:

            mkdir /Users/tlenaert/Desktop/test/build/Debug
    cd /Users/tlenaert/Desktop/test
    /Developer/usr/bin/g++-4.0 -o /Users/tlenaert/Desktop/test/build/Debug/test -L/Users/tlenaert/Desktop/test/build/Debug -L/opt/local/lib -L/opt/local/lib -F/Users/tlenaert/Desktop/test/build/Debug -filelist /Users/tlenaert/Desktop/test/build/test.build/Debug/test.build/Objects-normal/i386/test.LinkFileList -lboost_program_options-mt-1_35 -arch i386 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk
Undefined symbols:
  "boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, __gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) const", referenced from:
      vtable for boost::program_options::typed_value<__gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, char>in main.o
      vtable for boost::program_options::typed_value<int, char>in main.o
      vtable for boost::program_options::typed_value<double, char>in main.o
  "boost::program_options::detail::cmdline::cmdline(__gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)", referenced from:
      boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char**)in main.o
  "boost::program_options::validate(boost::any&, __gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int)", referenced from:
      void boost::program_options::validate<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, char>(boost::any&, __gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, __gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*, int)in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
                  "boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, __gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) const", referenced from:
                      vtable for boost::program_options::typed_value<__gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, char>in main.o
                      vtable for boost::program_options::typed_value<int, char>in main.o
                      vtable for boost::program_options::typed_value<double, char>in main.o
                  "boost::program_options::detail::cmdline::cmdline(__gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)", referenced from:
                      boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char**)in main.o
                  "boost::program_options::validate(boost::any&, __gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int)", referenced from:
                      void boost::program_options::validate<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, char>(boost::any&, __gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, __gnu_debug_def::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*, int)in main.o
                ld: symbol(s) not found
                collect2: ld returned 1 exit status
Build failed (3 errors)

IS there anyone here who cam across a similar problem or who can help me out?

Thanks a lot

Tom

====================
main.cpp
===================
#include <iostream>
#include <vector>
#include <string>
#include <boost/program_options.hpp>
namespace po = boost::program_options;

using namespace std;

int main (int argc, char * argv[]) {
        //setting up the simulation
        double run;
        double additional;
        int limit;
        
        po::options_description desc("Allowed options");
        desc.add_options()
                ("help", "produce help message")
                ("run,R", po::value<double>(&run)->default_value(1000), "identification of run")
                ("limit,L", po::value<int>(&limit)->default_value(1), "threshold for stochastic and deterministic dynamics")
                ("additional,A", po::value<double>(&additional)->default_value(20), "Additional years to run after threshold is reached")
                ("settings,S",po::value<vector<string> >(),"File with simulation settings")
                ("output,O",po::value<vector<string> >(),"Output file");
                

        po::variables_map vm;
        po::store(po::parse_command_line(argc, argv, desc), vm);
        po::notify(vm);

        if (vm.count("help")) {
                cout << desc << "n";
                return 1;
        }
        
        string inputfname;
        if(vm.count("settings")){
                inputfname = (vm["settings"].as<vector<string> >())[0];
                cout << "Input file is "<< inputfname << endl;
        }

        string ouputfname;
        if(vm.count("output")){
                ouputfname = (vm["output"].as<vector<string> >())[0];
                cout << "Output file is "<< ouputfname << endl;
        }
        
        
        return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net