链接Gecode在OS/X
的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
任何想法如何解决这个问题?
您可以使用Linux命令的文档里面的dylibs链接,如:
setevn LD_LIBRARY_PATH <dir
,如:在/ usr /本地/>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
我有同样的问题。有趣的是,编译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)。