0

我正在尝试从http://www.graphviz.org/Documentation.php中的“将 Graphviz 用作库”中运行一个示例。

#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;
    /* 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", Agdirected);
    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 pkg-config libgvc --cflags --libs*.c -o EXE -lgvc

然后我看到了这个结果:

graph.c: In function ‘main’:
graph.c:14:18: error: ‘Agdirected’ undeclared (first use in this function)
graph.c:14:18: note: each undeclared identifier is reported only once for each function it appears in
graph.c:15:2: error: too many arguments to function ‘agnode’
In file included from /usr/include/graphviz/types.h:717:0,
                 from /usr/include/graphviz/gvc.h:20,
                 from graph.c:1:
/usr/include/graphviz/graph.h:185:22: note: declared here
graph.c:16:2: error: too many arguments to function ‘agnode’
In file included from /usr/include/graphviz/types.h:717:0,
                 from /usr/include/graphviz/gvc.h:20,
                 from graph.c:1:
/usr/include/graphviz/graph.h:185:22: note: declared here
graph.c:17:2: error: too many arguments to function ‘agedge’
In file included from /usr/include/graphviz/types.h:717:0,
                 from /usr/include/graphviz/gvc.h:20,
                 from graph.c:1:
/usr/include/graphviz/graph.h:192:22: note: declared here
graph.c:7:11: warning: unused variable ‘a’ [-Wunused-variable]
graph.c:6:12: warning: variable ‘e’ set but not used [-Wunused-but-set-variable]

谁能帮我理解发生了什么?为什么编译器会抱怨这些函数中的这些参数?

谢谢!!!!

4

1 回答 1

0

我将您的代码保存为 gc,然后发出此命令行

gcc -Wall `pkg-config libgvc --cflags --libs` g.c -o EXE -lgvc

产生

g.c: In function ‘main’:
g.c:14:5: error: too few arguments to function ‘agopen’
/usr/local/include/graphviz/cgraph.h:266:18: note: declared here
g.c:7:14: warning: unused variable ‘a’ [-Wunused-variable]
g.c:6:15: warning: variable ‘e’ set but not used [-Wunused-but-set-variable]

然后我添加了miss参数

g = agopen("g", Agdirected, 0);

和小姐图书馆

gcc -Wall `pkg-config libgvc --cflags --libs` g.c -lgvc -lcgraph

现在代码编译和链接只有 2 个警告:

g.c: In function ‘main’:
g.c:7:14: warning: unused variable ‘a’ [-Wunused-variable]
g.c:6:15: warning: variable ‘e’ set but not used [-Wunused-but-set-variable]

我认为它可以工作,因为我已经从源代码构建了 graphviz,然后 pkg-config 是最新的......该程序仍然需要一些调试,运行它我得到:

./a.out

There is no layout engine support for "a.out"
Use one of: circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
Error: Layout was not done.  Missing layout plugins? 

该消息是因为默认情况下布局引擎使用 exe 名称(ieaout,gcc 编译和链接的默认值)作为布局字符串...

于 2013-10-25T12:41:14.287 回答