提问者:小点点

OSX上Boost与C++的链接器错误


我正在使用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);

编译,但不会链接。我会遇到一些神秘的链接错误,比如:

链接体系结构x86_64的CXX可执行文件主要未定义符号:“Boost::Program_Options::Validation_Error::Whath()const”,引用自:vtable for Boost::Program_Options::Invalid_Option_Value in IEEE1394_Camera.CXX.o vtable for Boost::Exception_Detail::Clone_Impl>;在IEEE1394_Camera.cxx.o vtable for Boost::EXCEPTION_DETAILE::ERROR_INFO_INJECTOR in IEEE1394_Camera.cxx.o vtable for Boost::EXCEPTION_DETALE::CLONE_IMPL>;在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(&S;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集合的符号

但是,只要删除“。refreshrate”选项,或者将其更改为std::string而不是int,就可以修复它。

我正在使用CMake进行编译,并且我已经尝试了Boost1.49和Boost1.5(我自己编译的)。我将Boost与darwin(默认)和gcc工具链混合使用,并使用内置的GCC4.2和Macports安装的4.7。不走运。

有什么想法吗?

更新:以下是我的完整链接命令(来自'make verbose=1'):

“/applications/cmake2.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。


共1个答案

匿名用户

好吧,我明白了,虽然我对细节还有点模糊。

我删除了所有内容,从XCode返回到常用的GCC4.2,并使用以下命令重建了Boost:

./B2--prefix=/users/rhand/development/boost-1.50/install/--layout=versioned--build-type=complete variant=release link=shared runtime-link=shared threading=single install

然后,我不得不修改我的CMake构建中的一些内容,以使其正确链接:

set(Boost_COMPILER "-xgcc42")

并设置一些环境变量:

BOOSTROOT=/Users/rhand/Development/boost-1.50/install/
BOOST_INCLUDEDIR=/Users/rhand/Development/boost-1.50/install/include/boost-1_50/
BOOST_LIBRARYDIR=/Users/rhand/Development/boost-1.50/install/lib

然后,一切都成功了。我不太确定问题出在哪里,除非是在指定发布版本或与所有共享库一起使用时的特殊情况。。。

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(osx|boost|c++|链接|器)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?