Gecode(4.3.0)文档指定在Mac上安装Gecode后,您可以按如下方式编译和链接示例:
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 :(得分:2)
我有同样的问题。有趣的是,Gecode中的examples文件夹中的所有源文件在编译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(见gecode mailing list)。
答案 1 :(得分:0)
您可以使用文档中的Linux命令链接dylib,例如:
setevn LD_LIBRARY_PATH <dir
,例如:/ usr / local /&gt;
g++ -I <dir>/include -c send-more-money.cpp
g++ -o send-more-money -L<dir>/lib send-more-money.o -lgecodesearch -lgecodeint -lgecodekernel -lgecodesupport