简体   繁体   English

无法使用点布局(graphviz作为库)

[英]Unable to use dot layout (graphviz as a library)

I use graphviz (v2.28.0) as a library in a C++ application and I would like to render graphs using the dot layout. 我将graphviz(v2.28.0)用作C ++应用程序中的库,我想使用点布局来绘制图形。 Everything works fine until I call the gvLayout(_context, _graph, "dot"); 一切正常,直到我调用gvLayout(_context,_graph,“ dot”); function which outputs the following error : 输出以下错误的函数:

 Error: Layout type: "dot" not recognized. Use one of:

I use the following library flags when linking : 链接时使用以下库标志:

-lgvc -lgraph -lpathplan -lcdt -lgvplugin_dot_layout

Calling dot from the Unix command line works as expected. 从Unix命令行调用dot可以正常工作。 What am I doing wrong ? 我究竟做错了什么 ?

You probably either already fixed this or gave up, but I ended up here so I'm sure someone else will... 您可能已经解决了这个问题或放弃了,但是我在这里结束了,所以我相信其他人会...

Plugins need to be loaded explicitly. 插件需要显式加载。 I'm not sure whether this is related to static linking or needs to be done whenever graphviz is used as a library. 我不确定这是否与静态链接有关,还是在将graphviz用作库时需要完成此操作。

This fixed dot for me: 这个固定的点对我来说:

extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
gvAddLibrary(gvc, &gvplugin_dot_layout_LTX_library);

I got this error when I added the "-O2" optimization flag to gcc when I compiled graphviz on macosx. 当我在macosx上编译graphviz时,在gcc中添加了“ -O2”优化标志时,出现了此错误。 When I removed that flag, the error went away. 当我删除该标志时,错误消失了。

According to a reply by Emden R. Gansner on the 'graphviz-interest' mailing list , this error message indicates that the software was unable to find the graphviz config file. 根据Emden R. Gansner对“ graphviz-interest”邮件列表答复 ,此错误消息表明该软件无法找到graphviz配置文件。

The graphviz config file ( config6 ) is used by the gvc library to load the various libgvplugin_... libraries on demand. gvc库使用graphviz配置文件( config6 )来gvc加载各种libgvplugin_...库。

Gansner also mentions that graphviz supports a GVBINDIR environment variable which, if defined, is used to specify the directory containing the graphviz config file. Gansner还提到graphviz支持GVBINDIR环境变量 ,如果定义了GVBINDIR变量 ,该变量将用于指定包含graphviz配置文件的目录。 This is also discussed at How to configure & package Graphviz for Mac App Store? 如何在Mac App Store中配置和打包Graphviz也对此进行了讨论 .

In my case (where I'm trying to include the graphviz libraries in an macOS/Objective-C framework), a framework subdirectory (called "Libraries") contains the config6 file plus these libgvplugin_... libraries (next to the regular graphviz libraries): 就我而言(在MacOS / Objective-C框架中尝试包含graphviz库),一个框架子目录(称为“库”)包含config6文件以及这些libgvplugin_...库(常规graphviz的旁边)库):

Libraries:
    config6
    libgvplugin_core.6.dylib
    libgvplugin_dot_layout.6.dylib
    libgvplugin_gd.6.dylib
    libgvplugin_neato_layout.6.dylib
    libgvplugin_quartz.6.dylib

From within one of the framework's classes, one could then set the GVBINDIR environment variable like this: 然后,可以从框架的某一类中设置GVBINDIR环境变量,如下所示:

NSBundle *containingBundle = [NSBundle bundleForClass:[self class]];
NSURL *librariesDirURL = [[containingBundle bundleURL] URLByAppendingPathComponent:@"Versions/A/Libraries" isDirectory:YES];
if (librariesDirURL) {
    setenv("GVBINDIR", (char*)[[librariesDirURL path] UTF8String], 1);
}

Setting the GVBINDIR environment variable is the only solution that worked for me. 设置GVBINDIR环境变量是唯一对我GVBINDIR的解决方案。

I've also tried the solutions mentioned by others above including loading the default graphviz plugins explicitly. 我还尝试了上面其他人提到的解决方案,包括显式加载默认的graphviz插件。 Eg, with _graphContext being defined as static GVC_t *_graphContext , this code: 例如,将_graphContext定义为static GVC_t *_graphContext ,此代码:

extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
extern gvplugin_library_t gvplugin_neato_layout_LTX_library;
extern gvplugin_library_t gvplugin_core_LTX_library;
extern gvplugin_library_t gvplugin_quartz_LTX_library;

lt_symlist_t lt_preloaded_symbols[] =
{
    { "gvplugin_dot_layout_LTX_library", &gvplugin_dot_layout_LTX_library},
    { "gvplugin_neato_layout_LTX_library", &gvplugin_neato_layout_LTX_library},
    { "gvplugin_core_LTX_library", &gvplugin_core_LTX_library},
    { "gvplugin_quartz_LTX_library", &gvplugin_quartz_LTX_library},
    { 0, 0}
};

_graphContext = gvContextPlugins(lt_preloaded_symbols, 1);

actually worked for me. 实际上为我工作。 Ie, this caused the graphviz plugins to load and the above mentioned error message ('Error: Layout type: "dot" not recognized. Use one of:') vanished. 即,这导致graphviz插件加载,并且上述错误消息(“错误:布局类型:“点”无法识别。请使用以下之一:)消失。 However, any subsequent call to gvLayout() then caused a graphviz crash ( EXC_BAD_ACCESS ) for me. 但是,随后对gvLayout()任何调用EXC_BAD_ACCESS对我造成graphviz崩溃( EXC_BAD_ACCESS )。

So for now I'm taking the environment variable approach. 所以现在我正在采用环境变量方法。

Do you use graphviz with dynamic library loading? 您是否将graphviz与动态库加载一起使用? In a static environment the following lines may help: 在静态环境中,以下几行可能会有所帮助:

#include "gvplugin.h"

extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
extern gvplugin_library_t gvplugin_neato_layout_LTX_library;
extern gvplugin_library_t gvplugin_core_LTX_library;
extern gvplugin_library_t gvplugin_quartz_LTX_library;
extern gvplugin_library_t gvplugin_visio_LTX_library;

lt_symlist_t lt_preloaded_symbols[] =
{
    { "gvplugin_dot_layout_LTX_library", &gvplugin_dot_layout_LTX_library},
    { "gvplugin_neato_layout_LTX_library", &gvplugin_neato_layout_LTX_library},
    { "gvplugin_core_LTX_library", &gvplugin_core_LTX_library},
    { "gvplugin_quartz_LTX_library", &gvplugin_quartz_LTX_library},
    { "gvplugin_visio_LTX_library", &gvplugin_visio_LTX_library},
    { 0, 0}
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM