首页 文章

在OSX上与Boost&C的链接器错误

提问于
浏览
0

我正在使用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可执行文件主要用于体系结构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 :: IEEE1394_Camera.cxx.o中的error_info_injector“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 :: IEEE1394_Camera.cxx.o中的allocator >>> const&,bool)(也许你的意思是: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 )找不到架构x86_64 collect2:错误:ld返回1退出状态

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

我正在使用CMake编译,我尝试过Boost 1.49和Boost 1.5(我自己编译) . 我使用darwin(默认)和gcc工具链,并使用内置的gcc4.2和安装了4.7的Macports来复制Boost . 没运气 .

有任何想法吗?

更新:这里's my full link command (from a '使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 /提高-1.50 /安装/ lib中/ libboost_exception.a

1 回答

  • 3

    好吧,我想出来了,虽然我对细节仍然有点模糊 .

    我把所有东西都擦掉了,从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
    

    然后,一切正常 . 我不确定问题是什么,除非它在指定发布版本或与所有共享库一起使用时是特别的...

相关问题