连接错误使用升压放大器&; C ++在OSX [英] Linker error with Boost & C++ on OSX

查看:202
本文介绍了连接错误使用升压放大器&; C ++在OSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写使用Boost的program_options支持小C ++程序。下面code:

 的boost :: program_options :: options_description递减(允许的选项);
desc.add_options()
    (.refreshrate,助推:: program_options ::值< INT>() - GT; DEFAULT_VALUE(50),帧之间的延时)
    (.location,助推:: program_options ::值<标准::字符串>(安培; __位置),摄像机位置)
    (。地址,助推:: program_options ::值<标准::字符串>(安培; __地址),摄像机的地址)
    ;
提高:: program_options :: variables_map VM;
提高:: program_options ::店(升压:: program_options :: parse_config_file(IFILE,递减,真),VM);
提高:: program_options ::通知(VM);

编译,但不能链接。我得到神秘的链接错误,如:


  

链接CXX可执行的主
  适用于建筑x86_64的未定义符号:
    的boost :: program_options :: VALIDATION_ERROR ::什么()const的,从引用:
       虚函数表升压:: program_options ::在IEEE1394_Camera.cxx.o invalid_option_value
       V表在IEEE1394_Camera.cxx.o的boost :: exception_detail :: clone_impl>
       虚函数表升压:: exception_detail :: error_info_injector在IEEE1394_Camera.cxx.o
       V表在IEEE1394_Camera.cxx.o的boost :: exception_detail :: clone_impl>
       虚函数表升压:: exception_detail :: error_info_injector在IEEE1394_Camera.cxx.o
  \"boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t,的std :: basic_string的,性病::分配器>常量和放大器;,的std :: basic_string的,性病::分配器>常量和放大器;),从引用:
       的std :: basic_string的,性病::分配器>常量和放大器;提高:: program_options ::验证:: get_single_string(的std ::向量,性病::分配器>的std ::分配器,性病::分配器>>>常量和放大器;,布尔)在IEEE1394_Camera.cxx.o
      (也许你的意思: boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t,的std :: basic_string的,性病::分配器>常量和放大器;,的std :: basic_string的,性病::分配器>常量和放大器;,INT))
  LD:符号(S)未找到x86_64的架构
  collect2:错误:LD返回1退出状态


然而,简单地删除.refreshrate选项,或将其更改为一个std ::字符串,而不是一个int,修复它。

我与CMake的编译和我尝试加速1.49和Boost 1.5(编译我自己)。我copmiled升压同时与达尔文(默认)和gcc工具,并使用内置的gcc4.2和MacPorts的安装4.7。没有运气。

任何想法?

更新的:这是我的完整链接命令(从'让VERBOSE = 1')


  

/应用/ 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轮候册,-search_paths_first轮候册,-headerpad_max_install_names CMakeFiles / main.dir / main.cxx.o -o主要/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



解决方案

好吧,我想通了这一点,但我还是有点模糊,以细节。

我抹去所有的东西,又回到股票gcc4.2从X code和使用这个命令重建升压:


  

./ B2 - preFIX = /用户/ rhand /开发/升压1.50 /安装/ --layout =版本控制--build型=完整的变种=发布链接=共享运行时链接=共享线程=单安装


然后,我不得不修改一些事情在我的CMake构建得到它正确链接:

 设置(Boost_COMPILER-xgcc42)

和设置一些环境变量:

  BOOSTROOT = /用户/ rhand /开发/升压1.50 /安装/
BOOST_INCLUDEDIR = /用户/ rhand /开发/升压1.50 /安装/有/升压1_50 /
BOOST_LIBRARYDIR = /用户/ rhand /开发/升压1.50 /安装/ lib目录

然后,一切正常。我不完全确定的问题是什么,除非是一些特别的东西在指定发布版本或与所有共享库去...

I'm writing a small C++ program using Boost's 'program_options' support. The following code:

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);

Compiles, but won't link. I get cryptic linking errors like:

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

However, simply removing the ".refreshrate" option, or changing it to a std::string instead of an int, fixes it.

I'm compiling with CMake, and I've tried Boost 1.49 and Boost 1.5 (compiled myself). I've copmiled Boost with both the darwin (default) and gcc toolchain, and using the built-in gcc4.2 and a Macports installed 4.7 . No luck.

Any ideas?

Update: Here's my full link command (from a '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

解决方案

Ok, I figured this out, although I'm still a bit fuzzy as to the details.

I wiped everything out, went back to the stock gcc4.2 from XCode and rebuilt Boost using this command:

./b2 --prefix=/Users/rhand/Development/boost-1.50/install/ --layout=versioned --build-type=complete variant=release link=shared runtime-link=shared threading=single install

Then, I had to modify some things in my CMake build to get it to link properly:

set(Boost_COMPILER "-xgcc42")

and Set some environment variables:

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

And then, everything works. I'm not exactly sure what the problem was, unless it's something special in specifying a Release build or going with all shared libraries...

这篇关于连接错误使用升压放大器&; C ++在OSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆