0

I am developping a program with QtCreator in which I use graphviz2.38.

I have done a minimale example to explain. Just consider this small code which transform a dot file in svg file:

#include <QCoreApplication>
#include <graphviz/gvc.h>
#include <graphviz/gvplugin.h>
#include <graphviz/cgraph.h>
#include <graphviz/cdt.h>
#include<iostream>
using namespace std;

void saveImageGV(){

    GVC_t *gvc= gvContext();
    extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
    gvAddLibrary(gvc, &gvplugin_dot_layout_LTX_library);
    FILE *fp = fopen(("ancestry.dot"), "r");
    Agraph_t *g = agread(fp,0);
    gvLayout(gvc, g, "dot");
    gvRender(gvc, g, "svg", fopen(("ancestry.svg"), "w"));
    gvFreeLayout(gvc, g);
    agclose(g);
    (gvFreeContext(gvc));
    return exit(0);
}


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    saveImageGV();
    return a.exec();
}

The compilation options are the following:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport


SOURCES += \
        main.cpp
QMAKE_LFLAGS += "-Wl,--rpath=lib/ "
QMAKE_LFLAGS += "-Wl,--dynamic-linker=lib/ld-linux-x86-64.so.2"

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
INCLUDEPATH += /usr/local/include/graphviz/

unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/ -lcdt
INCLUDEPATH += $$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib

unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/ -lcgraph
INCLUDEPATH += $$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib

unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/ -lgvc
INCLUDEPATH += $$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib

unix:!macx: LIBS += -L$$PWD/../../../usr/lib/graphviz/ -lgvplugin_dot_layout
INCLUDEPATH += $$PWD/../../../usr/lib/graphviz
DEPENDPATH += $$PWD/../../../usr/lib/graphviz

unix:!macx: LIBS += -L$$PWD/../../../usr/lib/graphviz/ -lgvplugin_core
INCLUDEPATH += $$PWD/../../../usr/lib/graphviz
DEPENDPATH += $$PWD/../../../usr/lib/graphviz

unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/ -lpathplan
INCLUDEPATH += $$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib

unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/ -lxdot
INCLUDEPATH += $$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib

I also provide you an example of graphviz dot code if needed for ancestry.dot:

graph {
    a -- b;
    b -- c;
    a -- c;
    d -- c;
    e -- c;
    e -- a;
}

In my lib folder, I have the following libraries:

ld-linux-x86-64.so.2  libc.so.6              libgvplugin_dot_layout.so.6  libxdot.so.4
libcdt.so.5           libgvc.so.6            libgvplugin_gd.so.6
libcgraph.so.6        libgvplugin_core.so.6  libpathplan.so.4

To load these libraries at execution time, I use the following script:

#!/bin/sh
appname=`basename $0 | sed s,\.sh$,,`

dirname=`pwd`
lib=/lib/

chmod +x $dirname/$appname

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$dirname$lib
echo $LD_LIBRARY_PATH

./$appname "$@"

When I execute my code, I get a segmentation fault ... Any idea of what is happening?

froz
  • 163
  • 1
  • 12
  • Possible duplicate of [Unable to use dot layout (graphviz as a library)](https://stackoverflow.com/questions/9602127/unable-to-use-dot-layout-graphviz-as-a-library) – Cinder Biscuits Oct 03 '18 at 20:14
  • You need to distribute the dynamic libraries with your application, yes. Please see https://stackoverflow.com/questions/9602127/unable-to-use-dot-layout-graphviz-as-a-library for a solution to your issue. (you must explicitly load the dot plugin) – Cinder Biscuits Oct 03 '18 at 20:15
  • Thank you cinder biscuits, I just edited my post. When I load the plugin with Chris Devereux s answer, I get a segmentation fault :( – froz Oct 03 '18 at 20:17
  • @froz change `ancestry.dot` to full-path – eyllanesc Oct 03 '18 at 21:05
  • I have tried but it does not change anything – froz Oct 03 '18 at 21:20
  • okay, but at least in the code it says "/path/of/ancestry.dot" to not have that doubt because if you put a relative path this should be relative to the executable that is in the build folder and not the project that often generates this type of problems, I also see that you do not do any verification which smells bad – eyllanesc Oct 03 '18 at 22:24
  • I believe my problem comes from library linking. This example that you can see is just a minimal example. I have checks and correct path for the complete code. I have updated my question – froz Oct 04 '18 at 09:39
  • Your debugger probably has a much better idea than anybody here. – n. m. could be an AI Oct 04 '18 at 09:40
  • Is it possible to use a debugger for a software compiled on another computer? Do you have a tuto? – froz Oct 04 '18 at 09:58
  • Yes it is, but you are compiling your own program. Chances that an external library is to blame are slim. Start by looking at the stack trace at the time of the crash. – n. m. could be an AI Oct 04 '18 at 13:54
  • With gdb I get the fllowing problem: Program received signal SIGSEGV, Segmentation fault. 0x00007ffff77695ee in ?? () from lib/libgvc.so.6 – froz Oct 04 '18 at 15:44

0 Answers0