2013-10-25 30 views
0

我試圖從運行一個例子「使用的Graphviz作爲庫」中http://www.graphviz.org/Documentation.php的Graphviz爲Library錯誤:參數太多的功能「agnode」

#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] 

誰能幫助我理解到底是怎麼回事?爲什麼編譯器在抱怨那些函數中的參數?

謝謝!!!!

+0

什麼是'Agdirected'?它應該是一個字符串?否則,你需要聲明它。此外,所有的錯誤信息都很清楚,其中大部分都是因爲你需要對一些函數進行很多爭論。 –

回答

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] 

然後我加入了思念參數

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配置是跟上時代的... 的程序仍然需要一些調試,運行它我得到:

./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名稱(即a.out,gcc編譯鏈接的缺省值)作爲佈局字符串...

+0

我做了你所說的,但是我仍然得到同樣的錯誤! 我使用的是基於Debian 7的系統,我從默認回購庫安裝了libgraphviz。 –

+0

我認爲這是因爲pkg-config信息可能很舊。編譯時嘗試添加-DWITH_CGRAPH。 – CapelliC

+0

-DWITH_CGRAPH解決了我的問題,非常感謝! –