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你知道怎么解决这个问题吗?
发布于 2014-11-22 00:42:13
我也有同样的问题。有趣的是,在编译Gecode期间,Gecode中examples文件夹中的所有源文件都被成功编译和链接。在尝试了所有类型的包含路径、库路径和库名称后,我放弃了,并做了一些研究。
这个问题似乎源于编译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非那样做不行。这归功于一位名叫马可·科雷亚的人(见gecode mailing list)。
发布于 2014-10-21 13:31:40
您可以在文档中使用Linux命令来链接dylib,例如:
setevn LD_LIBRARY_PATH <dir,,例如: /usr/local/>g++ -I <dir>/include -c send-more-money.cppg++ -o send-more-money -L<dir>/lib send-more-money.o -lgecodesearch -lgecodeint -lgecodekernel -lgecodesupporthttps://stackoverflow.com/questions/26315376
复制相似问题