【发布时间】:2015-12-02 05:22:29
【问题描述】:
我正在尝试使用自制软件来下载和构建诸如 boost、ceres-solver 之类的软件包。发生的情况是,我将尝试编译代码,没有任何特殊标志(g++ foo.cpp -o foo -I /usr/local/... 并且我也尝试过 clang++)并且我一直收到此错误:
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 来修复。它对诸如 shared_ptr 之类的 C++11 语法提出了反对意见:
/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.
如果不需要,我宁愿不编辑库源代码,希望开发人员做得很好?
有没有办法构建能够提供正确链接的库(有或没有自制软件)?目前我只是brew install <package> 我错过了什么明显的东西吗?还是我自己编译代码时搞砸了?
我在 Mac OS X 10.10.5 上, brew --config 给出了这个:
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 大部分都正确,至少据我所知?一切安装和构建都很好。
我使用 brew 安装了 gcc 并尝试使用 g++-5 和 gcc-5 命令编译库以避免clang,当我尝试在编译时传递-std=c++11 标志时遇到同样的问题 - g++-5 foo.cpp -o foo -I /usr/local/bar -std=c++11。这些都不起作用。
我还应该强调,当我尝试编译和运行附带的示例脚本时会发生这些情况,例如 boost,甚至不是我自己的脚本。我只是希望这些库至少大部分是正确的。
我也在这里查看了很多类似的问题,很多都没有答案,而那些有解决方案的问题,嗯,我尝试了很多解决方案,但它们也无济于事。我试过-lstdc++.6,我试过-stdlib=libstdc++。 -l 不会改变任何东西,-stdlib 会导致我上面描述的问题。
我能得到的任何帮助都会很棒,我已经为此工作了好几个星期了,这让我发疯了。
为清晰起见快速编辑:
所以当我输入时:
$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)
这不仅仅是 ceres,boost 也会出现类似的错误。
【问题讨论】:
-
使用 libc++ 而不是 libstdc++。如果您显示实际丢失的符号消息,则更容易看到发生了什么:) IIRC libstdc++ 是该库的较旧 GNU 版本。 libc++ 现在应该适用于大多数东西。并可能显示产生问题的确切步骤?
-
在上面添加,谢谢 :) 我使用 libstdc++ 的唯一原因是它实际上给了我一个不同的错误,我认为它可能有助于找出问题所在。
-
尝试输入
which g++和which clang++。听起来你的路径很可能搞砸了,你实际上并没有运行你认为的程序。如果您想准确指定要运行的二进制文件,可以在 bash 中使用./语法并指定二进制文件的完整路径 -
所以我实际上卸载了 gcc,因为它没有帮助,所以
which g++和which clang++分别给了我/usr/bin/g++和/usr/bin/clang++。还尝试添加-L /usr/local/lib,同样的错误。如果我使用-lceres -lglog,它可以工作,但我是否必须在每个库中都使用它,或者是否有可以编辑的路径? -
非常令人兴奋的是它终于可以工作了,@MarkSetchell
标签: c++ macos c++11 homebrew clang++