agopen seg faults using graph.h - ver < 2.3

I am modifying some old code using graph.h instead of cgraph.h, agopen seg faults, please instruct how to fix, here is the backtrace:

Program received signal SIGSEGV, Segmentation fault.
agclos (proto=0xbfffdb88) at graph.c:31
31        memclosure = memdisc->open(proto);
(gdb) bt
#0  agclos (proto=0xbfffdb88) at graph.c:31
#1  agopen (name=0x8064605 "root", desc=..., arg_disc=0xbfffdb88) at graph.c:50

 

`pkg-config --libs libgvc` -lgraph

Thank you.

I would have to have more

I would have to have more information to comment, but if you are using graph.h, why is the call to agopen using the agopen from cgraph? Is this what you wanted? Note that if your current graphviz was built using cgraph, the call pkg-config --libs libgvc is going to yield  -lgvc -lcgraph -lcdt, so cgraph will take precedence over any functions with the same name in libgraph. If the code thinks it is using the agopen from libgraph, there will only be two arguments, so that arg_disc that the agopen from libcgraph gets is some junk value.

In general, you can use graph.h to handle graphs, but if you want to use it in conjunction with the layout features of graphviz, you should use a version built with libgraph and not libcgraph.

This is what I did but it is

This is what I did but it is seg faulting in gvContext now:

#include <types.h>
#include <graphviz/graph.h>
#include <graphviz/gvc.h>

 

aginit();
Agraph_t* g;

GVC_t* gvc = gvContext();
g = agopen("root", AGDIGRAPH);

 

and I am compiling with:

pkg-config libgraph libgvc

If I don't link it with libgvc it cannot find the gvContext, render etc, functions.

 

You can probably get things

You can probably get things to compile and link, but you will still get a crash if you try to mix libgraph with a graphviz system relying on cgraph. The types are not binary compatible. If you want to call functions declared in gvc.h with a graphviz built using cgraph, you can only use the cgraph library.

The simplest solution would be to modify the code using graph.h to use cgraph.h. The conversion is fairly mechanical.

I linked it against libgraph

I linked it against libgraph but it is saying that it cannot find 

/usr/local/include/graphviz/graph.h:75:2: error: unknown type name ‘Agraphinfo_t’
/usr/local/include/graphviz/graph.h:87:2: error: unknown type name ‘Agnodeinfo_t’
/usr/local/include/graphviz/graph.h:98:2: error: unknown type name ‘Agedgeinfo_t’

are these defined in another header file?

thank you.

 

 

How do I link it to libgraph and not libcgraph?

Thank you for your prompt repsonse. You are right pkg-config is linking it with "-lgvc -lcgraph -lcdt", how do I link it with libgraph and not libcgraph? Currently this is my inlcude statement:

#include <gvc.h>

Thank you for your response,

Vidoje

How do I link it to libgraph and not libcgraph?

Thank you for your prompt repsonse. You are right pkg-config is linking it with "-lgvc -lcgraph -lcdt", how do I link it with libgraph and not libcgraph? Currently this is my inlcude statement:

#include <gvc.h>

Thank you for your response,

Vidoje

Recent comments