2

Gecode (4.3.0) のドキュメントには、Gecode を Mac にインストールした後、次のようにサンプルをコンパイルしてリンクできることが記載されています。

g++ -O3 -c money.cpp
g++ -framework gecode -o money money.o

コンパイルは成功しますが、リンクは次のように失敗します。

Undefined symbols for architecture x86_64:
  "Gecode::Gist::TextOutput::TextOutput(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      void Gecode::Driver::ScriptBase<Gecode::Space>::runMeta<Money, Gecode::DFS, Gecode::Options, Gecode::Driver::EngineToMeta>(Gecode::Options const&, Money*) in money.o
      void Gecode::Driver::ScriptBase<Gecode::Space>::runMeta<Money, Gecode::DFS, Gecode::Options, Gecode::RBS>(Gecode::Options const&, Money*) in money.o
  "Gecode::Driver::stop(Gecode::Support::Timer&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from:
      void Gecode::Driver::ScriptBase<Gecode::Space>::runMeta<Money, Gecode::DFS, Gecode::Options, Gecode::Driver::EngineToMeta>(Gecode::Options const&, Money*) in money.o
      void Gecode::Driver::ScriptBase<Gecode::Space>::runMeta<Money, Gecode::DFS, Gecode::Options, Gecode::RBS>(Gecode::Options const&, Money*) in money.o
  "Gecode::branch(Gecode::Home, Gecode::IntVarArgs const&, Gecode::IntVarBranch, Gecode::IntValBranch, bool (*)(Gecode::Space const&, Gecode::IntVar, int), void (*)(Gecode::Space const&, Gecode::BrancherHandle const&, unsigned int, Gecode::IntVar, int, int const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&))", referenced from:
      Money::Money(Gecode::Options const&) in money.o
ld: symbol(s) not found for architecture x86_64

これを解決する方法はありますか?

4

2 に答える 2

3

同じ問題がありました。興味深いことに、Gecode のサンプル フォルダーのすべてのソース ファイルは、Gecode のコンパイル中に正常にコンパイルおよびリンクされました。あらゆる種類のインクルード パス、ライブラリ パス、およびライブラリ名を試した後、あきらめていくつかの調査を行いました。

この問題は、Gecode 自体のコンパイルに起因しているようです。デフォルトの Xcode セットアップを使用してコンパイル/リンクする場合、つまり、clang (Apple LLVM 6.0) を呼び出す gcc (4.2.1) シンボリック リンクを使用する場合、Gecode とプログラムの両方が同じ標準ライブラリを使用していることを確認する必要があります。これは、古いバイナリ (元はネイティブ gcc で使用されていたもの) と新しいバイナリがあるためです。

gcc 4.9.2 (MacPorts を使用) を使用して Gecode をコンパイルしました。何らかの理由で、gcc 4.2.1/clang に戻しました。Gecode プログラムをコンパイルするために、-stdlib=libstdc++コンパイル/リンク命令を追加する必要がありました。これは古いバイナリにstdlib=libc++リンクし、新しいバイナリにリンクします。Send-More-Money をコンパイルすると、次のようになります。

g++ -c -stdlib=libstdc++ -I/usr/local/include money.cpp
g++ -stdlib=libstdc++ -L/usr/local/lib money.o -lgecodedriver -lgecodesearch -lgecodeminimodel -lgecodeint -lgecodekernel -lgecodesupport

一方、gcc 4.9.2 で Gecode プログラムをコンパイルするのは簡単でした。実際、g++ の新しいバージョンはオプションを受け入れません-stdlib。したがって、それはちょうど

g++ -c -I/usr/local/include money.cpp
g++ -L/usr/local/lib money.o -lgecodedriver -lgecodesearch -lgecodeminimodel -lgecodeint -lgecodekernel -lgecodesupport

それだけです。クレジットは Marco Correia の 1 人に贈られます ( gecode メーリング リストを参照してください)。

于 2014-11-21T16:42:12.720 に答える
0

ドキュメント内の Linux コマンドを使用して、次のように dylib をリンクできます。

  1. setevn LD_LIBRARY_PATH <dir例: /usr/local/>

  2. g++ -I <dir>/include -c send-more-money.cpp

  3. g++ -o send-more-money -L<dir>/lib send-more-money.o -lgecodesearch -lgecodeint -lgecodekernel -lgecodesupport

于 2014-10-21T05:31:40.320 に答える