我正在使用Boost的'program_options'支持編寫一個小型的C++程序。以下代碼:OSX上的Boost和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);
編譯但不會鏈接。我得到神祕的鏈接錯誤,如:
Linking CXX executable main Undefined symbols for architecture x86_64: "boost::program_options::validation_error::what() const", referenced from: 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 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&)", referenced from: 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 (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)) ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status
然而,僅僅刪除「.refreshrate」選項,或將其更改爲一個std ::字符串,而不是一個int,修復它。
我正在編譯CMake,我試過Boost 1.49和Boost 1.5(自己編譯)。我已經與達爾文(默認)和gcc工具鏈共同使用Boost,並使用內置的gcc4.2和Macports安裝的4.7。沒有運氣。
任何想法?
更新:這是我的完整鏈接命令(從「讓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庫列表中?這是一個你必須鏈接的編譯庫。 – 2012-08-16 00:32:00
是的..就像我說的,它編譯和運行就好,只要我不打算讀取Int值。 – Yeraze 2012-08-16 00:56:32
新的促進,所以只是想幫助。其中一個錯誤行給你一個建議:'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))'你有沒有試過他們認爲你可能意味着什麼? – ChiefTwoPencils 2012-08-16 02:33:19