使GraphViz在C ++中作为库工作的困难

时间:2010-05-21 21:36:36

标签: c++ dll visual-studio-2010 linker graphviz

正在研究一个程序,该程序将允许显示节点图,然后在节点本身更新时进行可视化更新。我是Visual Studio 2010的新手,并且遵循位于on the GraphViz website的GraphViz指南,以使GraphViz作为库工作。我有以下代码,这些代码直接来自上面链接的pdf。

#include <graphviz\gvc.h>
#include <graphviz\cdt.h>
#include <graphviz\graph.h>
#include <graphviz\pathplan.h>
using namespace std;

int main(int argc, char **argv)
{
    Agraph_t *g;
    Agnode_t *n, *m;
    Agedge_t *e;
    Agsym_t *a;
    GVC_t *gvc;

    /* set up a graphviz context */
    gvc = gvContext();

    /* parse command line args - minimally argv[0] sets layout engine */
    gvParseArgs(gvc, argc, argv);

    /* Create a simple digraph */
    g = agopen("g", AGDIGRAPH);
    n = agnode(g, "n");
    m = agnode(g, "m");
    e = agedge(g, n, m);

    /* Set an attribute - in this case one that affects the visible rendering */
    agsafeset(n, "color", "red", "");

    /* Compute a layout using layout engine from command line args */
    gvLayoutJobs(gvc, g);

    /* Write the graph according to -T and -o options */
    gvRenderJobs(gvc, g);

    /* Free layout data */
    gvFreeLayout(gvc, g);

    /* Free graph structures */
    agclose(g);

    /* close output file, free context, and return number of errors */
    return (gvFreeContext(gvc));
}

编译后,我收到以下错误,表明我没有正确链接。

1>main.obj : error LNK2019: unresolved external symbol _gvFreeContext referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _agclose referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _gvFreeLayout referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _gvRenderJobs referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _gvLayoutJobs referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _agsafeset referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _agedge referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _agnode referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _agopen referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _gvParseArgs referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _gvContext referenced in function _main

在VC ++目录中我有

  

C:\ Program Files(x86)\ Graphviz2.26.3 \ include in Include Directories

  库目录中的

C:\ Program Files(x86)\ Graphviz2.26.3 \ lib \ release \ lib

非常感谢任何帮助以帮助实现这一目标。谢谢。

2 个答案:

答案 0 :(得分:1)

您通常需要将.lib文件添加到链接区域第一部分中的附加输入。

更正:属性 - >链接器 - >输入 - >附加依赖项。

答案 1 :(得分:1)

在其他库输入下,您必须添加graphviz导入库,无论它被调用,都在您添加路径的lib目录中。也许是graphviz.lib?