gpt4 book ai didi

c++ - gcc 链接器和 OGDF "undefined reference to ` ogdf::Initialization::Initialization( )'"

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:47:21 26 4
gpt4 key购买 nike

我正在尝试获取 OGDF正在努力查看它是否适合我的项目,但我在使用示例程序时遇到了问题。

我正在尝试编译 this example program :

#include <ogdf/basic/Graph.h>
#include <ogdf/basic/graph_generators.h>
#include <ogdf/layered/DfsAcyclicSubgraph.h>

using namespace ogdf;

int main()
{
Graph G;
randomSimpleGraph(G, 10, 20);
DfsAcyclicSubgraph DAS;
DAS.callAndReverse(G);
G.writeGML("test.gml");

return 0;
}

使用这个命令:

$g++ -pthread -I ./OGDF/ -L ./OGDF/_release/ -lOGDF test2.cpp 

但是我得到以下错误

/tmp/ccbpkfdt.o: In function `main':
test2.cpp:(.text+0x12): undefined reference to `ogdf::Graph::Graph()'
test2.cpp:(.text+0x2e): undefined reference to `ogdf::randomSimpleGraph(ogdf::Graph&, int, int)'
test2.cpp:(.text+0x4e): undefined reference to `ogdf::AcyclicSubgraphModule::callAndReverse(ogdf::Graph&)'
test2.cpp:(.text+0x62): undefined reference to `ogdf::Graph::writeGML(char const*) const'
test2.cpp:(.text+0x7f): undefined reference to `ogdf::Graph::~Graph()'
test2.cpp:(.text+0xa1): undefined reference to `ogdf::Graph::~Graph()'
/tmp/ccbpkfdt.o: In function `__static_initialization_and_destruction_0(int, int)':
test2.cpp:(.text+0xfb): undefined reference to `ogdf::Initialization::Initialization()'
test2.cpp:(.text+0x112): undefined reference to `ogdf::Initialization::~Initialization()'
/tmp/ccbpkfdt.o: In function `ogdf::DfsAcyclicSubgraph::DfsAcyclicSubgraph()':
test2.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphC2Ev[_ZN4ogdf18DfsAcyclicSubgraphC5Ev]+0x16): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
/tmp/ccbpkfdt.o: In function `ogdf::DfsAcyclicSubgraph::~DfsAcyclicSubgraph()':
test2.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphD2Ev[_ZN4ogdf18DfsAcyclicSubgraphD5Ev]+0xb): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
collect2: error: ld returned 1 exit status

我尝试使用 OGDF 中的包含编译 hello world,但我仍然得到:

undefined reference to `ogdf::Initialization::Initialization()'

我认为我没有正确链接或其他什么?

最佳答案

在与库链接时,您必须非常小心输入内容的顺序。尝试将 test2.cpp 放在 -lOGDF 之前,像这样:

g++ -pthread -I ./OGDF/ -L ./OGDF/_release/ test2.cpp -lOGDF 

关于c++ - gcc 链接器和 OGDF "undefined reference to ` ogdf::Initialization::Initialization( )'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20352535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com