3

我正在尝试按照此处提供的libguide将 graphviz 用作 C++ 项目的库。但是,即使编译附录中的示例,我也遇到了问题。当我尝试使用 gcc 编译 demo.c 时,我得到以下输出:

$ gcc -I/usr/local/Cellar/graphviz/2.28.0/include/ demo.c -L/usr/local/Cellar/graphviz/2.28.0/lib/ -lgvc -lgraph -lcdt
demo.c: In function ‘main’:
demo.c:14: error: ‘Agdirected’ undeclared (first use in this function)
demo.c:14: error: (Each undeclared identifier is reported only once
demo.c:14: error: for each function it appears in.)
demo.c:15: error: too many arguments to function ‘agnode’
demo.c:16: error: too many arguments to function ‘agnode’
demo.c:17: error: too many arguments to function ‘agedge’

Agdirected 在 cgraph.h 中找到,但如果我将 demo.c 中的包含更改为

#include <graphviz/gvc.h>
#include <graphviz/cgraph.h>

然后所有的地狱都崩溃了(两个标题之间的声明主要是冲突的)。如何在不为所有这些冲突而头疼的情况下包含必要的标题?

Mac OS X 10.8.3、Graphviz 2.28.0、GCC 4.2.1

4

2 回答 2

1

It seems after some experimentation that adding the flag

#define WITH_CGRAPH

has the effect of including cgraph.h, which gets rid of the "'Agdirected' undeclared" error.

The other errors can be fixed by changing the command line option in gcc from -lgraph to -lcgraph

于 2013-04-15T05:19:24.830 回答
1

您使用的 libguide 是 cgraph 版本,它假定 Graphviz 2.30 或更高版本。在该版本中,已经提供了#define WITH_CGRAPH。

于 2013-05-08T15:49:29.873 回答