Unable to use dot layout (graphviz as a library)

2019-02-27 14:41发布

问题:

I use graphviz (v2.28.0) as a library in a C++ application and I would like to render graphs using the dot layout. Everything works fine until I call the 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. What am I doing wrong ?

回答1:

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.

This fixed dot for me:

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


回答2:

I got this error when I added the "-O2" optimization flag to gcc when I compiled graphviz on macosx. When I removed that flag, the error went away.



回答3:

Do you use graphviz with dynamic library loading? 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}
};


标签: c++ graphviz dot