2015-09-06 24 views
6

私はhomebrewを使ってboost、ceres-solverなどのパッケージをダウンロードしてビルドしようとしています。何が起こるかというと、私がしようとすると、コンパイルコードを、特別なフラグなし(g++ foo.cpp -o foo -I /usr/local/...と私は++あまりにも打ち鳴らすを試してみた)ということであり、私は一貫して、このエラーを取得する:ld:アーキテクチャx86_64のシンボルが見つかりませんでした。clang:linkerコマンドが失敗しました。

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を呼び出すことで修正されていないという事実に関連するエラーを表示しています。かなり良いを行っている私は、私が開発者を期待したいために持っていない場合

/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. 

私はむしろライブラリのソースコードを編集しないと思います。それはshared_ptrのようなC++ 11の構文に異議をスローしますジョブ?

正しいリンクを与えるライブラリを作成する方法はありますか?現在私はただbrew install <package>私は何か明白な行方不明ですか?あるいは、コード自体をコンパイルするときに私は何かをねじっていますか?

私は、Mac OS X 10.10.5上だし、これを与える--config BREW:

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はそのほとんどを適切に処理しているようです。すべてがインストールされ、うまく構築されます。

私はビールを使用してGCCをインストールおよびg ++使用してライブラリをコンパイルしようとした - 打ち鳴らすを避けるために、5とgcc-5コマンドを、私はコンパイル時に-std=c++11フラグを渡ししようとすると、私は同じ問題を取得する - g++-5 foo.cpp -o foo -I /usr/local/bar -std=c++11 。これらの作品はありません。

私はまた、自分自身のスクリプトでさえもブーストなどのサンプルスクリプトをコンパイルして実行しようとしたときに、これらが発生することを強調する必要があります。私は、図書館が少なくとも大部分は正しいと思っています。

ここでも多くの似たような質問がありましたが、回答が多く、解決策があるものもありました。私は多くのソリューションを試してみましたが、どちらも役に立ちません。私は-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) 

そして、これは単なるセレスないが、同じようなエラーがブーストのために発生するo。マークSetchellへ

+1

libC++ではなくlibstdC++を使用します。あなたが実際に失われたシンボルメッセージを表示すると、何が起こっているのかが分かりやすくなります:) IIRC libstdC++は古いGNU版のライブラリです。 libC++は今ではほとんどのもので動作するはずです。そして、問題を引き起こすための正確な手順を示していますか? – JCx

+1

上記に追加、ありがとう:)私はlibstdC++を使用した唯一の理由は、実際に私に別のエラーを与えたからです。何が間違っているのか調べるのに役立つと思いました。 – bzcheeseman

+0

「which g ++」と「which clang ++」と入力してみてください。あなたのパスが乱れていると思われ、実際にあなたが思っているプログラムを実際に実行しているわけではありません。実行するバイナリを正確に指定する場合は、bashで '。/'構文を使用し、バイナリへのフルパスを指定することができます –

答えて

7

ありがとう:リンクするライブラリを指定する必要は、自作を使用した場合

/usr/local/libに目を保つことが重要です。

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

同じ答えが(Qtはこれまでのところ、含まれています)私が試した他のすべてと同様、ブーストライブラリのために働くようだ:働い

最終的なコードはこれでした。

+1

それを並べ替えてコミュニティと共有するためによくできました。あなたはあなた自身の答えを受け入れて、それを行うためのポイントを得ることができます。 –

関連する問題