【问题标题】:gcc Linker and OGDF "undefined reference to `ogdf::Initialization::Initialization()'"gcc 链接器和 OGDF “未定义引用 `ogdf::Initialization::Initialization()'”
【发布时间】:2013-12-19 14:12:16
【问题描述】:

我正在尝试让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()'

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

【问题讨论】:

  • 你让它工作了吗?
  • 我添加了一个解决方案。试试看:)

标签: c++ ogdf


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    使用 OGDF 作为共享库时,您必须使用 -DOGDF_DLL 构建程序。

    请看这里:http://www.ogdf.net/doku.php/tech:defines

    【讨论】:

      猜你喜欢
      • 2011-12-26
      • 2013-04-28
      • 2013-03-08
      • 2016-10-10
      • 1970-01-01
      • 2017-12-29
      • 2019-09-24
      • 2022-12-01
      • 1970-01-01
      相关资源
      最近更新 更多