1

I want to use Graphviz in my Qt application, but I haven't used any third-party libraries before. I've found the following video on YouTube which shows how to use third-party DLLs in Qt. I've downloaded Graphviz 2.38 and copied all headers to my program folder as in the video, and copied all dlls to debug and release builds, and added these dlls as libraries in .pro file. But I still get "undefined reference" errors to functions from graphviz libraries. So does the method shown in the video still work in Qt6 ? Or did I do something wrong ?

.pro file:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    arith.h \
    cdt.h \
    cgraph.h \
    color.h \
    geom.h \
    graph.h \
    gvc.h \
    gvcext.h \
    gvcjob.h \
    gvcommon.h \
    gvconfig.h \
    gvplugin.h \
    gvplugin_device.h \
    gvplugin_layout.h \
    gvplugin_loadimage.h \
    gvplugin_render.h \
    gvplugin_textlayout.h \
    gvpr.h \
    mainwindow.h \
    pack.h \
    pathgeom.h \
    pathplan.h \
    textpara.h \
    textspan.h \
    types.h \
    usershape.h \
    xdot.h

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\ann.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\cdt.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\cgraph.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\gvc.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\gvplugin_core.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\gvplugin_dot_layout.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\gvplugin_gd.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\gvplugin_gdiplus.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\gvplugin_neato_layout.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\gvplugin_pango.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\Pathplan.dll"

LIBS += "C:\...\build-BSP_Emulator_alpha-Desktop_Qt_6_2_0_MinGW_64_bit-Debug\debug\vmalloc.dll"

FORMS +=

main.cpp:

#include "mainwindow.h"
#include "gvc.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    //QApplication a(argc, argv);
    MainWindow main_window;
    main_window.setGeometry(100,100,1000,1300);
    main_window.show();
    GVC_t *gvc;
    Agraph_t *g;
    FILE *fp;
    gvc = gvContext();
    if (argc > 1)
    fp = fopen(argv[1], "r");
    else
    fp = stdin;
    g = agread(fp, 0);
    gvLayout(gvc, g, "dot");
    gvRender(gvc, g, "plain", stdout);
    gvFreeLayout(gvc, g);
    agclose(g);
    return (gvFreeContext(gvc));
}
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • I suggest you use cmake instead of qmake, and then there'll be a wealth of resources to help you. qmake is deprecated at this point. Do not be fooled by default templates provided by Qt Creator: they work, but they are often outdated and not how things should be done. Qt has had cmake support since Qt 4 at the very least, so this is old news at this point. – Kuba hasn't forgotten Monica Oct 25 '21 at 14:46

1 Answers1

0

In the 'LIBS +=' section you must set not the *.dll files, but rather .lib(on windows) or (lib.a) on unix

When you download library you probably have files like:

library.dll - file with compiled code used only by operating system
library.lib (win32) - file used by linker to connect you program with library

Dll isn't need to compile program at all, it's used only when system startups your program.

crayze
  • 386
  • 3
  • 12
  • I've added every .lib file from graphviz libraries using LIBS+= but I still get "undefined reference" errors. – Юрій Ярош Nov 19 '21 at 16:38
  • @ЮрійЯрош so linker can't find those *.lib files or files doesn't contain those symbols inside (wrong library or version), there is not other way. You can look inside *.lib file, check this: https://stackoverflow.com/questions/305287/how-to-see-the-contents-of-windows-library-lib – crayze Nov 24 '21 at 19:09