Boost logo

Boost Users :

Subject: [Boost-users] program_options bad_any_cast in XCode
From: Thijs Koerselman (thijskoerselman.lists_at_[hidden])
Date: 2009-10-26 11:25:11


Hi,

Somehow I keep getting exceptions related to the use of strings when I
compile my program in Xcode. If I use strings in my program arguments I get
an bad_any_cast exception from the store() method.

If I compile the same program from the command line directly it works fine,
but I can't seem to figure out what the difference is between the two build
commands that is causing this behavior.

I compiled the program from the command line like this:
g++-4.2 -arch i386 -I/opt/local/include -L/opt/local/lib
-lboost_program_options-mt -o waveform_manbuild main.cpp

Xcode uses the following:

CompileC
build/waveform.build/Release/waveform.build/Objects-normal/i386/main.o
main.cpp normal i386 c++ com.apple.compilers.gcc.4_2

cd /Users/foo/waveform

setenv LANG en_US.US-ASCII

/Developer/usr/bin/gcc-4.2 -x c++ -arch i386 -fmessage-length=0 -pipe
-Wno-trigraphs -fpascal-strings -fasm-blocks -Os -mdynamic-no-pic
-Wreturn-type -Wunused-variable -isysroot /Developer/SDKs/MacOSX10.5.sdk
-fvisibility=hidden -fvisibility-inlines-hidden -mmacosx-version-min=10.5
-gdwarf-2 -iquote
/Users/foo/waveform/build/waveform.build/Release/waveform.build/waveform-generated-files.hmap
-I/Users/foo/waveform/build/waveform.build/Release/waveform.build/waveform-own-target-headers.hmap
-I/Users/foo/waveform/build/waveform.build/Release/waveform.build/waveform-all-target-headers.hmap
-iquote
/Users/foo/waveform/build/waveform.build/Release/waveform.build/waveform-project-headers.hmap
-F/Users/foo/waveform/build/Release
-I/Users/foo/waveform/build/Release/include -I/opt/local/include
-I/Users/foo/waveform/build/waveform.build/Release/waveform.build/DerivedSources/i386
-I/Users/foo/waveform/build/waveform.build/Release/waveform.build/DerivedSources
-c /Users/foo/waveform/main.cpp -o
/Users/foo/waveform/build/waveform.build/Release/waveform.build/Objects-normal/i386/main.o

The (very simple) test program is listed below. I hope someone can spot the
problem. It's driving me nuts.

Cheers,
Thijs

PS: I'm using OS10.6.1 and Xcode 3.2.1

#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/program_options.hpp>

using namespace std;
namespace po = boost::program_options;

int main (int ac, char * av[]) {
 po::options_description desc("Allowed options");
desc.add_options()
    ("help", "produce help message")
    ("input-file,i", po::value< vector<string> >(), "input file")
;

po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm); /// << exception thrown
here
po::notify(vm);

if (vm.count("help")) {
    cout << desc << "\n";
    return 1;
}
 if (vm.count("input-file")) {
    vector<string> input_files = vm["input-file"].as< vector<string> >();
vector<string>::const_iterator it = input_files.begin();
for(; it!=input_files.end(); ++it)
cout<< *it << endl;
 } else {
    cout << "No input file(s).\n";
}
 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