使用Graphviz作为带有gcc的库

时间:2015-05-12 16:37:25

标签: c gcc graphviz

我发现了一个非常简单的例子,使用graphviz作为库(我也查看了相同名称的文档),但是我不能阻止程序在找到该行时崩溃:gvc = gvContext ();

以下是该计划:

#include <gvc.h>

int main(int argc, char **argv)
{
    Agraph_t *g;
    Agnode_t *n, *m;
    Agedge_t *e;
    Agsym_t *a;
    GVC_t *gvc;
    printf("0\n");
    /* set up a graphviz context */
    gvc = gvContext();
    printf("1\n");
    /* parse command line args - minimally argv[0] sets layout engine */
    gvParseArgs(gvc, argc, argv);
    printf("2\n");
    /* Create a simple digraph */
    g = agopen("g", Agdirected, 0);
    n = agnode(g, "n", 1);
    m = agnode(g, "m", 1);
    e = agedge(g, n, m, 0, 1);
    /* 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));
}

最后是编译和执行行(我打算将来有可移植代码):

gcc -Wall dot2.c -o dot -L / usr / lib -lcgraph -lgvc -lgraph -I /home/svin/CPP/graphviz-2.38.0/lib/gvc -I / home / svin / CPP /graphviz-2.38.0/lib/common/ -I /home/svin/CPP/graphviz-2.38.0/lib/pathplan/ -I /home/svin/CPP/graphviz-2.38.0/lib/cgraph/ - 我/home/svin/CPP/graphviz-2.38.0/lib/cdt /

./ dot -Tgif -o abc.gif

我知道为什么会出现seg故障和核心转储? 谢谢!

0 个答案:

没有答案