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

时间:2012-08-16 00:27:36

标签: c++ gcc boost linker

我正在使用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”,引自:        IEEE 1394_Camera.cxx.o中的boost :: program_options :: invalid_option_value的vtable        vtable for boost :: exception_detail :: clone_impl&gt;在IEEE1394_Camera.cxx.o中        IEEE 1394_Camera.cxx.o中的boost :: exception_detail :: error_info_injector的vtable        vtable for boost :: exception_detail :: clone_impl&gt;在IEEE1394_Camera.cxx.o中        IEEE 1394_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&gt; const&amp;,std :: basic_string,std :: allocator&gt; const&amp; )“,引用自:        std :: basic_string,std :: allocator&gt;常量和放大器; IEEE1394_Camera.cxx.o中的boost :: program_options :: validators :: get_single_string(std :: vector,std :: allocator&gt;,std :: allocator,std :: allocator&gt;&gt;&gt; const&amp;,bool)       (也许你的意思是:boost :: program_options :: validation_error :: validation_error(boost :: program_options :: validation_error :: kind_t,std :: basic_string,std :: allocator&gt; const&amp;,std :: basic_string,std :: allocator &gt; const&amp;,int))   ld:找不到架构x86_64的符号   collect2:错误:ld返回1退出状态

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

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

有什么想法吗?

更新:这是我的完整链接命令(来自'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

1 个答案:

答案 0 :(得分: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

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