我正在尝试使用 gcc 4.8(通过 MacPorts 安装)编译 boost::program_options 示例之一, http ://svn.boost.org/svn/boost/trunk/libs/program_options/example/first.cpp。但是,我不断收到错误:
架构 x86_64 的未定义符号: “boost::program_options::to_internal(std::basic_string, std::allocator > const&)”,引用自: std::vector, std::allocator >, std::allocator, std::allocator > > > boost::program_options::to_internal, std::allocator > >(std::vector, std::allocator >, std ::allocator, std::allocator > > > const&) 在 ccEWnIGV.o “boost::program_options::options_description::options_description(std::basic_string, std::allocator > const&, unsigned int, unsigned int)”,引用自: ccEWnIGV.o 中的 _main “boost::program_options::invalid_option_value::invalid_option_value(std::basic_string, std::allocator > const&)”,引用自: ccEWnIGV.o 中的 void boost::program_options::validate(boost::any&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, double*, long) "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) ",引用自: 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) 在 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&> )”,引用自: boost::program_options::basic_command_line_parser::extra_parser(boost::function1, std::allocator >, std::basic_string, std::allocator > >, std::basic_string, std::allocator > const&>) 在 ccEWnIGV 中。 ○ “boost::program_options::detail::cmdline::cmdline(std::vector, std::allocator >, std::allocator, std::allocator > > > const&)”,引用自: boost::program_options::basic_command_line_parser::basic_command_line_parser(int, char const* const*) 在 ccEWnIGV.o “boost::program_options::operator >&, boost::program_options::options_description const&)”,引用自: ccEWnIGV.o 中的 _main “boost::program_options::abstract_variables_map::operator[](std::basic_string, std::allocator > const&) const”,引用自: boost::program_options::variables_map::operator[](std::basic_string, std::allocator > const&) ccEWnIGV.o 中的 const “boost::program_options::error_with_option_name::substitute_placeholders(std::basic_string, std::allocator > const&) const”,引用自: ccEWnIGV.o 中 boost::program_options::invalid_option_value 的 vtable ccEWnIGV.o 中 boost::program_options::validation_error 的 vtable ETC...
boost 库是通过 MacPorts 安装的,将头文件/opt/local/include
和库文件放在/opt/local/lib
. 使用的编译命令是:
$ g++ -I/opt/local/include first.cpp -L/opt/local/lib -lboost_program_options-mt
使用 g++ 4.8 (即阶乘、hermite 等)编译仅标头的 boost 函数可以正常工作。
我觉得奇怪的是,如果我使用 llvm-g++ 编译器,这个例子可以编译:
$ llvm-g++ -I/opt/local/include first.cpp -L/opt/local/lib -lboost_program_options-mt
$ g++ -v 使用内置规范。 COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin12/4.8.1/lto-wrapper 目标:x86_64-apple-darwin12 线程模型:posix gcc 版本 4.8.1 (MacPorts gcc48 4.8.1_3)\
$llvm-g++ -v Apple LLVM 5.0 版(clang-500.2.79)(基于 LLVM 3.3svn) 目标:x86_64-apple-darwin13.0.0 线程模型:posix\
为什么这个例子不能用 gcc 4.8 编译?有任何想法吗?有没有办法来解决这个问题?
更新:该示例还使用 clang++ 编译