【发布时间】:2012-08-12 07:52:15
【问题描述】:
我正在使用 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”,引用自: IEEE1394_Camera.cxx.o 中 boost::program_options::invalid_option_value 的 vtable IEEE1394_Camera.cxx.o 中 boost::exception_detail::clone_impl > 的 vtable IEEE1394_Camera.cxx.o 中 boost::exception_detail::error_info_injector 的 vtable IEEE1394_Camera.cxx.o 中 boost::exception_detail::clone_impl > 的 vtable IEEE1394_Camera.cxx.o 中 boost::exception_detail::error_info_injector 的 vtable “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) in 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& , 整数)) 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
【问题讨论】:
-
您是否将 Boost.program_options 添加到所需的 Boost 库列表中?这是一个必须链接的编译库。
-
是的..就像我说的,只要我不打算读取 Int 值,它就可以编译和运行。
-
Boost 新手,所以只是想提供帮助。错误行之一是给你一个建议:
boost::program_options::validators::get_single_string(std::vector, std::allocator >, std::allocator, std::allocator > > > const&, bool) in IEEE1394_Camera.cxx.o (*******maybe you meant: 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))你试过他们认为你的意思吗? -
不,因为要更改的行深埋在 Boost 的代码中。所以我怀疑问题出在其他地方。