ld:找不到架构x86_64的符号,clang:链接器命令失败 [英] ld: symbols not found for architecture x86_64, clang: linker command failed

查看:251
本文介绍了ld:找不到架构x86_64的符号,clang:链接器命令失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自制软件下载并构建诸如boost,ceres-solver之类的软件包.发生的是,我将尝试编译代码,而没有任何特殊标志(g++ foo.cpp -o foo -I /usr/local/...,我也尝试过clang ++),并且始终收到此错误:

I'm trying to use homebrew to download and build packages like boost, ceres-solver, stuff like that. What happens is that I will try and compile code, without any special flags (g++ foo.cpp -o foo -I /usr/local/... and I've tried clang++ too) and I get this error consistently:

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

所以我环顾四周,解决方案是使用-stdlib=libstdc++标志.我尝试了一下,现在它给了我以下错误:苹果提供了旧版本的libstdc++,但不能通过调用-std=c++11-std=c++14来解决.它引发对C ++ 11语法(例如shared_ptr)的反对:

So I looked around and the solution is to use the -stdlib=libstdc++ flag. I tried it, and now it gives me errors related to the fact that apple ships an old version of the libstdc++, doesn't get fixed by invoking -std=c++11 or -std=c++14. It throws up objections to C++11 syntax like the shared_ptr:

/usr/local/include/ceres/internal/port.h:62:12: error: no member named
      'shared_ptr' in namespace 'std'
using std::shared_ptr;
      ~~~~~^
...
/usr/local/include/ceres/solver.h:629:15: error: expected member name or ';'
      after declaration specifiers
    shared_ptr<ParameterBlockOrdering> inner_iteration_ordering;
    ~~~~~~~~~~^
5 errors generated.

如果不想,我宁愿不编辑库源代码,希望开发人员做得很好?

I'd rather not edit the library source code if I don't have to, I'd hope the devs have done a pretty good job?

有没有一种方法可以构建能够提供正确链接的库(带有或不带有自制软件)?目前我只是brew install <package>我是否缺少明显的东西?还是我在编译代码本身时搞砸了?

Is there a way to build libraries (with or without homebrew) that will give the correct linking? Currently I just brew install <package> am I missing something obvious? Or am I screwing something up when I compile the code itself?

我在Mac OS X 10.10.5上,并且brew --config给出了这一点:

I'm on Mac OS X 10.10.5, and brew --config gives this:

HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: 03ad27453de01adc29cbf941bd29a2dfb54a9960
Last commit: 69 minutes ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: 8-core 64-bit ivybridge
OS X: 10.10.5-x86_64
Xcode: 6.4
CLT: 6.4.0.0.1.1435007323
Clang: 6.1 build 602
X11: N/A
System Ruby: 2.0.0-p481
Perl: /usr/bin/perl
Python: /usr/local/bin/python => /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Ruby: /usr/bin/ruby
Java: N/A

运行$arch给出:i386

$clang++ -v给出:

Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

我还应该补充一点,如果有旧版本或某些问题,我会尝试清理计算机.我所看到的一切都表明此错误是由构建时的不正确链接引起的,但是似乎brew能够正确地执行大多数操作,至少据我所知?一切都会安装并正常运行.

I should add that I've tried cleaning out my computer in case there was an old version or something mucking things up. Everything I've seen says this error is caused by improper linking at build time, but it seems like brew does most of that properly, at least as far as I can tell? Everything installs and builds fine.

我已经使用brew安装了gcc,并尝试使用g ++-5和gcc-5命令来编译库以避免clang,并且在尝试在编译时传递-std=c++11标志时遇到了相同的问题- g++-5 foo.cpp -o foo -I /usr/local/bar -std=c++11.这些都不起作用.

I've installed gcc using brew and tried to compile the library using the g++-5 and the gcc-5 command to avoid clang and I get the same problem when I try to pass the -std=c++11 flag at compile time - g++-5 foo.cpp -o foo -I /usr/local/bar -std=c++11. None of these work.

我还应该强调,当我尝试编译并运行示例脚本(例如boost,甚至是我自己的脚本)时,就会发生这些情况.我只是希望这些库至少在大多数情况下是正确的.

I should also emphasize that these happen when I try to compile and run the example scripts that come with, for example, boost, not even my own scripts. I'm just sort of hoping that the libraries are at least mostly correct.

我在这里也查看了很多类似的问题,很多问题都没有答案,但是有解决方案的问题,嗯,我尝试了很多解决方案,但是它们都没有帮助.我试过-lstdc++.6,我试过-stdlib=libstdc++. -l不会更改任何内容,-stdlib会导致上述问题.

I've also looked at a lot of similar questions here, many are unanswered and the ones that have solutions, well, I've tried many of the solutions and they don't help either. I've tried -lstdc++.6, I've tried -stdlib=libstdc++. The -l doesn't change anything, the -stdlib causes the issues I described above.

我能得到的任何帮助都会很棒,我已经为此工作了几周了,这真让我发疯.

Any help I can get would be great, I've been working on this for weeks now and it's driving me nuts.

为清楚起见,快速

所以当我输入:

$g++ cerestest.cpp -o ceres -I /usr/local/include/eigen3

$clang++ cerestest.cpp -o ceres -I /usr/local/include/eigen3

我得到:

Undefined symbols for architecture x86_64:
  "ceres::Solve(ceres::Solver::Options const&, ceres::Problem*, ceres::Solver::Summary*)", referenced from:
      _main in cerestest-ef733e.o
  "ceres::Solver::Summary::Summary()", referenced from:
      _main in cerestest-ef733e.o
  "ceres::Problem::AddResidualBlock(ceres::CostFunction*, ceres::LossFunction*, double*)", referenced from:
      _main in cerestest-ef733e.o
  "ceres::Problem::Problem()", referenced from:
      _main in cerestest-ef733e.o
  "ceres::Problem::~Problem()", referenced from:
      _main in cerestest-ef733e.o
  "google::LogMessage::stream()", referenced from:
      ceres::AutoDiffCostFunction<CostFunctor, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>::AutoDiffCostFunction(CostFunctor*) in cerestest-ef733e.o
      ceres::internal::AutoDiff<CostFunctor, double, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>::Differentiate(CostFunctor const&, double const* const*, int, double*, double**) in cerestest-ef733e.o
      void ceres::internal::Make1stOrderPerturbation<ceres::Jet<double, 1>, double, 1>(int, double const*, ceres::Jet<double, 1>*) in cerestest-ef733e.o
      void ceres::internal::Take0thOrderPart<ceres::Jet<double, 1>, double*>(int, ceres::Jet<double, 1> const*, double*) in cerestest-ef733e.o
      void ceres::internal::Take1stOrderPart<ceres::Jet<double, 1>, double, 0, 1>(int, ceres::Jet<double, 1> const*, double*) in cerestest-ef733e.o
  "google::LogMessageFatal::LogMessageFatal(char const*, int)", referenced from:
      void ceres::internal::Make1stOrderPerturbation<ceres::Jet<double, 1>, double, 1>(int, double const*, ceres::Jet<double, 1>*) in cerestest-ef733e.o
      void ceres::internal::Take0thOrderPart<ceres::Jet<double, 1>, double*>(int, ceres::Jet<double, 1> const*, double*) in cerestest-ef733e.o
      void ceres::internal::Take1stOrderPart<ceres::Jet<double, 1>, double, 0, 1>(int, ceres::Jet<double, 1> const*, double*) in cerestest-ef733e.o
  "google::LogMessageFatal::LogMessageFatal(char const*, int, google::CheckOpString const&)", referenced from:
      ceres::AutoDiffCostFunction<CostFunctor, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>::AutoDiffCostFunction(CostFunctor*) in cerestest-ef733e.o
      ceres::internal::AutoDiff<CostFunctor, double, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>::Differentiate(CostFunctor const&, double const* const*, int, double*, double**) in cerestest-ef733e.o
  "google::LogMessageFatal::~LogMessageFatal()", referenced from:
      ceres::AutoDiffCostFunction<CostFunctor, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>::AutoDiffCostFunction(CostFunctor*) in cerestest-ef733e.o
      ceres::internal::AutoDiff<CostFunctor, double, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>::Differentiate(CostFunctor const&, double const* const*, int, double*, double**) in cerestest-ef733e.o
      void ceres::internal::Make1stOrderPerturbation<ceres::Jet<double, 1>, double, 1>(int, double const*, ceres::Jet<double, 1>*) in cerestest-ef733e.o
      void ceres::internal::Take0thOrderPart<ceres::Jet<double, 1>, double*>(int, ceres::Jet<double, 1> const*, double*) in cerestest-ef733e.o
      void ceres::internal::Take1stOrderPart<ceres::Jet<double, 1>, double, 0, 1>(int, ceres::Jet<double, 1> const*, double*) in cerestest-ef733e.o
  "google::InitGoogleLogging(char const*)", referenced from:
      _main in cerestest-ef733e.o
  "google::base::CheckOpMessageBuilder::ForVar2()", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* google::MakeCheckOpString<int, int>(int const&, int const&, char const*) in cerestest-ef733e.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* google::MakeCheckOpString<int, ceres::DimensionType>(int const&, ceres::DimensionType const&, char const*) in cerestest-ef733e.o
  "google::base::CheckOpMessageBuilder::NewString()", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* google::MakeCheckOpString<int, int>(int const&, int const&, char const*) in cerestest-ef733e.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* google::MakeCheckOpString<int, ceres::DimensionType>(int const&, ceres::DimensionType const&, char const*) in cerestest-ef733e.o
  "google::base::CheckOpMessageBuilder::CheckOpMessageBuilder(char const*)", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* google::MakeCheckOpString<int, int>(int const&, int const&, char const*) in cerestest-ef733e.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* google::MakeCheckOpString<int, ceres::DimensionType>(int const&, ceres::DimensionType const&, char const*) in cerestest-ef733e.o
  "google::base::CheckOpMessageBuilder::~CheckOpMessageBuilder()", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* google::MakeCheckOpString<int, int>(int const&, int const&, char const*) in cerestest-ef733e.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* google::MakeCheckOpString<int, ceres::DimensionType>(int const&, ceres::DimensionType const&, char const*) in cerestest-ef733e.o
  "ceres::Solver::Summary::BriefReport() const", referenced from:
      _main in cerestest-ef733e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这不仅是问题,对于助推器也会发生类似的错误.

And this is not just ceres, similar errors occur for boost also.

推荐答案

感谢Mark Setchell:

Thanks to Mark Setchell:

使用自制软件时,注意/usr/local/lib很重要,需要指定链接库.

Keeping an eye on /usr/local/lib is important when using homebrew, the linking libraries need to be specified.

起作用的最终代码是这样:

The final code that worked was this:

g++ cerestest.cpp -o ceres -lglog -lceres -I /usr/local/include

对于Boost库以及我尝试过的所有其他库(到目前为止,都包含Qt),相同的答案似乎也适用.

The same answer seems to work for the boost libraries, as well as all the others I've tried (Qt included, so far).

这篇关于ld:找不到架构x86_64的符号,clang:链接器命令失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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