2014-10-11 62 views
0

的Gecode(4.3.0)的文件規定,在Mac上安裝Gecode後,就可以編譯和鏈接示例如下:鏈接Gecode在OS/X

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 

任何想法如何解決這個問題?

回答

0

您可以使用Linux命令的文檔裏面的dylibs鏈接,如:

  1. setevn LD_LIBRARY_PATH <dir,如:在/ usr /本地/>

  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

1

我有同樣的問題。有趣的是,編譯Gecode期間,Gecode中的示例文件夾中的所有源文件都已編譯並鏈接成功。在嘗試了各種包含路徑,庫路徑和庫名後,我放棄了一些研究。

看來問題源於編譯Gecode本身。如果您使用默認的Xcode設置編譯/鏈接,即使用調用clang(Apple LLVM 6.0)的gcc(4.2.1)符號鏈接,則應確保Gecode和您的程序都使用相同的標準庫。這是因爲有舊的二進制文件(最初與本地gcc一起使用)和較新的二進制文件。

我使用gcc 4.9.2編譯Gecode(使用MacPorts)。出於某種原因,我切換回gcc 4.2.1/clang。 爲了編譯我的Gecode程序,我必須添加-stdlib=libstdc++來編譯/鏈接指令。這鏈接到較舊的二進制文件,而stdlib=libc++鏈接到較新的二進制文件。 編譯發送-更多金錢應該是這樣的:

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(見gecode mailing list)。