I'm trying to compile one of the boost::program_options examples, http://svn.boost.org/svn/boost/trunk/libs/program_options/example/first.cpp, using gcc 4.8 (installed via MacPorts). However, I keep getting errors:
Undefined symbols for architecture x86_64: "boost::program_options::to_internal(std::basic_string, std::allocator > const&)", referenced from: std::vector, std::allocator >, std::allocator, std::allocator > > > boost::program_options::to_internal, std::allocator > >(std::vector, std::allocator >, std::allocator, std::allocator > > > const&) in ccEWnIGV.o "boost::program_options::options_description::options_description(std::basic_string, std::allocator > const&, unsigned int, unsigned int)", referenced from: _main in ccEWnIGV.o "boost::program_options::invalid_option_value::invalid_option_value(std::basic_string, std::allocator > const&)", referenced from: void boost::program_options::validate(boost::any&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, double*, long) in ccEWnIGV.o "boost::program_options::error_with_option_name::error_with_option_name(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&, int)", referenced from: boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&, int) in ccEWnIGV.o "boost::program_options::detail::cmdline::set_additional_parser(boost::function1, std::allocator >, std::basic_string, std::allocator > >, std::basic_string, std::allocator > const&>)", referenced from: boost::program_options::basic_command_line_parser::extra_parser(boost::function1, std::allocator >, std::basic_string, std::allocator > >, std::basic_string, std::allocator > const&>) in ccEWnIGV.o "boost::program_options::detail::cmdline::cmdline(std::vector, std::allocator >, std::allocator, std::allocator > > > const&)", referenced from: boost::program_options::basic_command_line_parser::basic_command_line_parser(int, char const* const*) in ccEWnIGV.o "boost::program_options::operator >&, boost::program_options::options_description const&)", referenced from: _main in ccEWnIGV.o "boost::program_options::abstract_variables_map::operator[](std::basic_string, std::allocator > const&) const", referenced from: boost::program_options::variables_map::operator[](std::basic_string, std::allocator > const&) const in ccEWnIGV.o "boost::program_options::error_with_option_name::substitute_placeholders(std::basic_string, std::allocator > const&) const", referenced from: vtable for boost::program_options::invalid_option_value in ccEWnIGV.o vtable for boost::program_options::validation_error in ccEWnIGV.o etc...
The boost libraries were installed via MacPorts, placing the header files in /opt/local/include
and library files in /opt/local/lib
. The compile command used was:
$ g++ -I/opt/local/include first.cpp -L/opt/local/lib -lboost_program_options-mt
Compiling header-only boost functions work fine using g++ 4.8 i.e factorial, hermite etc.
What I find strange is that this example compiles if I use the llvm-g++ compiler:
$ llvm-g++ -I/opt/local/include first.cpp -L/opt/local/lib -lboost_program_options-mt
$ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin12/4.8.1/lto-wrapper Target: x86_64-apple-darwin12 Thread model: posix gcc version 4.8.1 (MacPorts gcc48 4.8.1_3)\
$ llvm-g++ -v Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) Target: x86_64-apple-darwin13.0.0 Thread model: posix\
Why doesn't this example compile with gcc 4.8? Any ideas? Is there a way to fix this?
Update: The example also compiles using clang++