为什么会失败的graphviz上gvLayout? [英] Why does Graphviz fail on gvLayout?
问题描述
再一次,我在这里写C时不真正了解我在做什么...
Once again, here I am writing C without really knowing what I'm doing...
我拼凑一个简单的函数,我可以从一个C#程序,需要一个DOT字符串,输出格式和文件名,并使用Graphviz的渲染图调用。
I've slapped together a simple function that I can call from a C# program that takes a DOT string, an output format, and a file name and renders a graph using Graphviz.
#include "types.h"
#include "graph.h"
#include "gvc.h"
#define FUNC_EXPORT __declspec(dllexport)
// Return codes
#define GVUTIL_SUCCESS 0
#define GVUTIL_ERROR_GVC 1
#define GVUTIL_ERROR_DOT 2
#define GVUTIL_ERROR_LAYOUT 3
#define GVUTIL_ERROR_RENDER 4
FUNC_EXPORT int RenderDot(char * dotData, const char * format,
const char * fileName) {
Agraph_t * g; // The graph
GVC_t * gvc; // The Graphviz context
int result; // Result of layout and render operations
// Create a new graphviz context
gvc = gvContext();
if (!gvc) return GVUTIL_ERROR_GVC;
// Read the DOT data into the graph
g = agmemread(dotData);
if (!g) return GVUTIL_ERROR_DOT;
// Layout the graph
result = gvLayout(gvc, g, "dot");
if (result) return GVUTIL_ERROR_LAYOUT;
// Render the graph
result = gvRenderFilename(gvc, g, format, fileName);
if (result) return GVUTIL_ERROR_RENDER;
// Free the layout
gvFreeLayout(gvc, g);
// Close the graph
agclose(g);
// Free the graphviz context
gvFreeContext(gvc);
return GVUTIL_SUCCESS;
}
它编译罚款,但是当我把它,我得到 GVUTIL_ERROR_LAYOUT
。起初,我以为这可能是我是如何宣布我的P / Invoke签名,所以我从一个C程序,而不是测试,但它还是没有以同样的方式。
It compiles fine, but when I call it, I get GVUTIL_ERROR_LAYOUT
. At first, I thought it might have been how I was declaring my P/Invoke signature, so I tested it from a C program instead, but it still failed in the same way.
RenderDot("digraph graphname { a -> b -> c; }", "png", "C:\testgraph.png");
我错过了什么?
修改
如果有它与我如何编译code做一个偶然的机会,这里是我使用的命令:
If there's a chance it has to do with how I'm compiling the code, here's the command I'm using:
cl gvutil.c /I "C:\Program Files (x86)\Graphviz2.26\include\graphviz"
/LD /link /LIBPATH:"C:\Program Files (x86)\Graphviz2.26\lib\release"
gvc.lib graph.lib cdt.lib pathplan.lib
我一直在关注本教程说明如何使用的Graphviz作为一个库,所以我链接到它列出的.lib文件。
I've been following this tutorial that explains how to use Graphviz as a library, so I linked to the .lib files that it listed.
推荐答案
Graphviz的负载布局,根据配置文件,我还没有复制到我的应用程序的目录信息动态渲染插件。
Graphviz loads layout and rendering plugins dynamically based on information in a configuration file, which I had not copied to my application's directory.
这篇关于为什么会失败的graphviz上gvLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!