【发布时间】: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 支持,所以这已经是老新闻了。