我正在使用 Boost 的“program_options”支持编写一个小型 C++ 程序。以下代码:
boost::program_options::options_description desc("Allowed options");
desc.add_options()
(".refreshrate", boost::program_options::value< int >()->default_value(50), "Delay between frames")
(".location", boost::program_options::value<std::string>(&__Location), "Camera Location")
(".address", boost::program_options::value<std::string>(&__Address), "Address of Camera")
;
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_config_file(ifile, desc, true), vm);
boost::program_options::notify(vm);
编译,但不会链接。我收到神秘的链接错误,例如:
链接 CXX 可执行 main 架构 x86_64 的未定义符号:“boost::program_options::validation_error::what() const”,引用自:vtable for boost::program_options::invalid_option_value in IEEE1394_Camera.cxx.o vtable for boost::exception_detail ::clone_impl > in IEEE1394_Camera.cxx.o vtable for boost::exception_detail::error_info_injector in IEEE1394_Camera.cxx.o vtable for boost::exception_detail::clone_impl > in IEEE1394_Camera.cxx.o vtable for boost::exception_detail::error_info_injector在 IEEE1394_Camera.cxx.o "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&)”,引用自:std::basic_string, std::allocator > const& boost::program_options::validators::get_single_string(std::vector, std::allocator >, std::allocator, std::allocator > > > const&, bool) 在 IEEE1394_Camera.cxx .o(也许你的意思是: 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)) ld:未找到架构 x86_64 collect2 的符号:错误:ld 返回 1 退出状态program_options::validation_error::kind_t, std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&, int)) ld: 未找到架构 x86_64 collect2: 错误: ld 返回 1 个退出状态program_options::validation_error::kind_t, std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&, int)) ld: 未找到架构 x86_64 collect2: 错误: ld 返回 1 个退出状态
但是,只需删除“.refreshrate”选项,或将其更改为 std::string 而不是 int,即可修复它。
我正在使用 CMake 进行编译,并且尝试过 Boost 1.49 和 Boost 1.5(自己编译)。我已经使用 darwin(默认)和 gcc 工具链编译了 Boost,并使用了内置的 gcc4.2 和安装了 Macports 的 4.7 。没运气。
有任何想法吗?
更新:这是我的完整链接命令(来自“make VERBOSE=1”):
"/Applications/CMake 2.8-8.app/Contents/bin/cmake" -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1 /opt/local/bin/g++-mp-4.7 -Wl,- search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/main.dir/main.cxx.o -o main /Users/rhand/Development/boost-1.50/install/lib/libboost_program_options.a /Users/rhand/Development/boost-1.50/install /lib/libboost_timer.a /Users/rhand/Development/boost-1.50/install/lib/libboost_chrono.a /Users/rhand/Development/boost-1.50/install/lib/libboost_system.a /Users/rhand/Development/boost -1.50/install/lib/libboost_exception.a