【问题标题】:Apple Mach-O Linker (ld) Error. ld: -r and -dead-strip cannot be used togetherApple Mach-O 链接器 (ld) 错误。 ld: -r 和 -dead-strip 不能一起使用
【发布时间】:2017-06-16 13:56:33
【问题描述】:

XCode 5.0.1 在成功编译 161 个 C++ 项目文件后给我一个错误。 有很多 Apple Mach-O Linker Error 问题,但没有一个对我有帮助。

错误信息如下:

ld: -r and -dead_strip cannot be used together
clang: error: linker command failed with exit code 1
 (use -v to see invocation)

我的构建设置中的链接部分如下图所示:

Linker Section of XCode 5.0.1

谁能告诉我如何解决这个错误?

更新

当我将 Dead Code Stripping 设置为 No 时,我得到 19 个链接错误。对于ReleaseDebugMach-O Type 设置为Dynamic Library。 这种情况下的错误如下:

Undefined symbols for architecture x86_64:
      "boost::re_detail_106000::perl_matcher<__gnu_cxx::__normal_iterator<wchar    _t const*, std::basic_string<wchar_t, std::char_traits<wchar_t>,     std::allocator<wchar_t> > >,     std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<wchar_t     const*, std::basic_string<wchar_t, std::char_traits<wchar_t>,     std::allocator<wchar_t> > > > >, boost::regex_traits<wchar_t,     boost::cpp_regex_traits<wchar_t> >     >::construct_init(boost::basic_regex<wchar_t,     boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > > const&,     boost::regex_constants::_match_flags)", referenced from:
      boost::re_detail_106000::perl_matcher<__gnu_cxx::__normal_iterator<wchar_    t const*, std::basic_string<wchar_t, std::char_traits<wchar_t>,      std::allocator<wchar_t> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<wchar_t const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > >, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > >::perl_matcher(__gnu_cxx::__normal_iterator<wchar_t const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, __gnu_cxx::__normal_iterator<wchar_t const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, boost::match_results<__gnu_cxx::__normal_iterator<wchar_t const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<wchar_t const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > > >&, boost::basic_regex<wchar_t, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator<wchar_t const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >) in AdWrksTagDataFactory.o

错误信息如下:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

在一些类似的问题中,我看到这可能是由于 Boost 的多个版本造成​​的,但我已经检查过了。

【问题讨论】:

    标签: c++ xcode5 linker-errors osx-yosemite linker-flags


    【解决方案1】:

    只需将Dead Code Stripping 设置为No。当此选项设置为 Yes 时,Xcode 将在链接期间添加-dead_strip 标志,在链接可重定位二进制文​​件时不支持

    【讨论】:

    • 感谢您的回复,但我已经检查过了。它显示了 10 个链接错误。
    • 您遇到什么错误?它们可能与您的原始问题无关。
    • 我已经在问题中更新了它们。请看一看。
    • @d0mbn00b 老实说,这些问题现在看起来与您的原始问题完全无关,可能是另一个 SO 问题的主题。
    • 显然,使用不同的链接器设置会出现不同的链接错误。所以一开始我发布了我得到最少错误数的那个。
    猜你喜欢
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多