【问题标题】:Is this a proper way of using graphviz as a library?这是将graphviz用作库的正确方法吗?
【发布时间】:2021-12-10 23:49:20
【问题描述】:

我想在我的 Qt 应用程序中使用 Graphviz,但我之前没有使用过任何第三方库。我在 YouTube 上找到了以下video,它展示了如何在 Qt 中使用第三方 DLL。我已经下载了 Graphviz 2.38 并将所有标题复制到我的程序文件夹中,如视频中所示,并将所有 dll 复制到调试和发布版本,并将这些 dll 作为库添加到 .pro 文件中。但是我仍然收到来自 graphviz 库的函数的“未定义引用”错误。那么视频中显示的方法在 Qt6 中仍然有效吗?还是我做错了什么?

.pro 文件:

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));
}

【问题讨论】:

  • 我建议你使用cmake而不是qmake,然后会有大量的资源来帮助你。此时不推荐使用 qmake。不要被 Qt Creator 提供的默认模板所迷惑:它们可以工作,但它们通常已经过时,而不是应该如何做。 Qt 至少从 Qt 4 开始就有 cmake 支持,所以这已经是老新闻了。

标签: c++ qt qmake


【解决方案1】:

在 'LIBS +=' 部分,您不能设置 *.dll 文件,而是 .lib(on windows) 或 (lib.a) on unix

当您下载库时,您可能有如下文件:

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根本不需要编译程序,它只在系统启动程序时使用。

【讨论】:

  • 我已经使用 LIBS+= 从 graphviz 库中添加了每个 .lib 文件,但仍然出现“未定义引用”错误。
  • @ЮрійЯрош 所以链接器找不到那些 *.lib 文件或文件中不包含那些符号(错误的库或版本),没有其他方法。您可以查看 *.lib 文件,检查:stackoverflow.com/questions/305287/…
猜你喜欢
  • 2011-03-20
  • 2010-09-16
  • 2013-09-25
  • 1970-01-01
  • 1970-01-01
  • 2012-05-11
  • 2018-12-31
  • 2021-04-29
  • 1970-01-01
相关资源
最近更新 更多