gpt4 book ai didi

c++ - Graphviz 作为 Windows 中的库

转载 作者:行者123 更新时间:2023-12-02 10:22:38 25 4
gpt4 key购买 nike

我正在就 Graphviz 库与您联系。我在 Windows 上使用 graphviz 作为 c++ 代码中的库和 qt creator 时发现了一个错误。

基于 Documentation 中的示例,我使用以下函数将点文件转换为 png 文件:

bool saveImageGV(){       

GVC_t *gvc= gvContext();

gvAddLibrary(gvc, &gvplugin_dot_layout_LTX_library);

gvAddLibrary(gvc, &gvplugin_core_LTX_library);

gvAddLibrary(gvc, &gvplugin_gd_LTX_library);

FILE *fp = fopen((pathTmp + ".dot").c_str(), "r");

Agraph_t *g = agread(fp,0);

gvLayout(gvc, g, "dot");

FILE *fp2 = fopen((pathTmp + ".png").c_str(), "w");

gvRender(gvc, g, "png", fp2);

gvFreeLayout(gvc, g);

agclose(g); fclose(fp); fclose(fp2);

return (gvFreeContext(gvc));

}

看来,在 linux 上,此功能与 graphviz 2.30 配合得很好,我成功地将我的 dot 文件转换为 png 文件。
但是,当我使用 Windows 库时,我遇到了具有相同功能的段错误。
我的调查让我认为问题可能来自 .dll 库,因为在 linux 上,它适用于 2.30 版本,但不适用于 2.38 版本的库。使用windows,2.30和2.38导致同样的segmentation fault错误。

它是一个众所周知的错误吗?它是否存在另一种在 Windows 上将点文件转换为 png 文件的方法?我从“Graphviz2.38\lib\release\lib”文件夹链接库,并从“Graphviz2.38\lib\release\dll”文件夹中获取dll。

如果您需要更多信息,我提前感谢您的回复。

最佳答案

graphviz FAQ

可能是因为 stdio 版本错误

我在 Visual Studio 中发生了段错误,这是解决方案(使用/std:c++latest 所以语法不符合标准,代码仅供理解)

Agiodisc_t my_iodisc = {
.afread = [](void* chan, char* buf, int bufsize)->int
{
return fread(buf, 1, bufsize, (FILE*)chan);
},
.putstr = [](void* chan,const char* buf)->int
{
return fwrite(buf, 1, strlen(buf), (FILE*)chan);
},
.flush = [](void* chan)->int
{
return fflush((FILE*)chan);
}
};
Agdisc_t my_disc = {
.mem = NULL, // use system default
.id = NULL, // use system default
.io = &my_iodisc
};
FILE* p_file = fopen("1.gv", "r");
Agraph_t* g = agread(p_file, &my_disc);
fclose(p_file);

关于c++ - Graphviz 作为 Windows 中的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59459010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com