I am trying to compile one example of boost :: program_options, 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 ... Acceleration libraries were installed through MacPorts, placing header files in /opt/local/include and library files in /opt/local/lib . Used compilation command:
$ g++ -I/opt/local/include first.cpp -L/opt/local/lib -lboost_program_options-mt
Compiling boost-only boost functions works fine using g ++ 4.8 ie factorial, germite, etc.
It seems strange to me 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 is this example not compiling with gcc 4.8? Any ideas? Is there any way to fix this?
Update: the example also compiles using clang ++