Is this a proper way of using graphviz as a library? - c++

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

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.

Related

How linux and g++ understand what include path it needs to use?

I'm not quite completely understand how linux or g++ (gcc) define what include path it need to use to find some package. Here is what I mean:
I actually have a c++ project in QtCreator and I use qmake build system. I include in my code a header-only framework file, which needs a Boost of one of the last version. I have already in my system boost-1.64.0, but it's too old, so I've installed boost-1.80.0. But when I try to build the program a compilation error raises with the text:
{name_of_my_pro_file}.pro: rpm boost1.64.0-devel is not installed!!!
I thought if I just replace boost folder in /usr/include/ or /usr/local/include/ with folder of the newer boost version linux can use it instead of older one. But the error mentioned above still raises. I've tried to edit boost folder name in Makefile. Directly in my .pro file there is not any mentions about boost. But nothing helped me. I can handle it only when I renamed boost-1.80.0 folder to boost-1.64.0. And now it works.
It seems that name boost-1.64.0 is written somewhere in the system and it doesn't see any other packages.
I guess that I just don't understand how to work with this stuff correctly and doing something wrong. Can somebody explain what should I do?
My distro is Oracle Linux Server 8.4.
EDIT:
My .pro file:
QT += core gui network xml
QMAKE_CXXFLAGS += -std=c++0x
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TilesDataProvider
TEMPLATE = app
#DESTDIR = ./output
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_DEPRECATED_WARNINGS
CONFIG += no_abi_dump
INCLUDEPATH += \
$$PWD \
$$PWD\guts \
$$PWD\SRTM \
$$PWD\tileSources \
/usr/include
CONFIG(release, debug|release){
message(release)
TARGET = TilesDataProvider
OBJECTS_DIR = tmp/TilesDataProvider/release
MOC_DIR = tmp/TilesDataProvider/moc
}
CONFIG(debug, debug|release){
message(debug)
TARGET = TilesDataProvider_d
OBJECTS_DIR = tmp/TilesDataProvider/debug
MOC_DIR = tmp/TilesDataProvider/moc
DEFINES += _DEBUG
}
SOURCES += \
main.cpp \
tileSources/MapTileSource.cpp \
tileSources/SrtmTileSource.cpp \
guts/Position.cpp \
guts/t_task.cpp \
guts/MapConversions.cpp \
SRTM/altdatabank.cpp \
SRTM/altdatamap.cpp \
SRTM/geoid.cpp \
SRTM/srtm_coordinate.cpp \
SRTM/t_geodata.cpp \
SRTM/t_pageid.cpp \
t_image.cpp \
tilesdataprovider.cpp
HEADERS += \
tileSources/MapTileSource.h \
tileSources/SrtmTileSource.h \
guts/MapGraphics_global.h \
guts/Position.h \
guts/t_task.h \
guts/MapConversions.h \
SRTM/altdatabank.h \
SRTM/altdatamap.h \
SRTM/geoid.h \
SRTM/srtm_coordinate.h \
SRTM/t_geodata.h \
SRTM/t_pageid.h \
SRTM/tiff_param.h \
t_image.h \
tilesdataprovider.h

Can't get Qt Creator to Properly Compile OpenCV

I am trying to compile a Qt project and it seems like OpenCV is having problems. From what I have read so far, this could likely be a compiler/linkage problem. I have tried a couple different compilers without any success. Other libraries seem to be fine (libtiff, STD, other Qt libraries), but OpenCV is causing problems. I haven't for the life of me been able to make any progress on fixing it, any suggestions would be much appreciated. Posted below are things that I believe might be valuable in finding a solution.
Qt Makefile (.pro):
QT += core gui multimedia widgets multimediawidgets opengl
TARGET = LAUWebCalTag
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
laumemoryobject.cpp \
lauwebcamerawidget.cpp \
lauvideosurface.cpp \
lauvideoglwidget.cpp \
laucaltagglwidget.cpp \
laucaltagglobject.cpp
HEADERS += \
laumemoryobject.h \
lauwebcamerawidget.h \
lauvideosurface.h \
lauvideoglwidget.h \
laucaltagglwidget.h \
laucaltagglobject.h
RESOURCES += lauwebcameracapture.qrc
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
win32 {
INCLUDEPATH += $$quote(C:\Users\Sam\Downloads\opencv\build\include) $$quote(C:/usr/include)
INCLUDEPATH += $$quote(C:\Users\Sam\Downloads\tiff-4.0.9\tiff-4.0.9\libtiff)
DEPENDPATH += $$quote(C:\Users\Sam\Downloads\opencv\build\include) $$quote(C:/usr/include)
LIBS += -L$$quote(C:\usr\libs) -lopengl32
LIBS += -L$$quote(C:\Users\Sam\Downloads\opencv\build\x64\vc12\lib)
LIBS += -L$$quote(C:\Users\Sam\Downloads\tiff-4.0.9\tiff-4.0.9\libtiff) -llibtiff_i
CONFIG(release, debug|release): LIBS += -lopencv_world310
CONFIG(debug, debug|release): LIBS += -lopencv_world310d
}
Issues:
[Screenshot of Resulting Compile Issues]
Build and Run:
[Build and Run Kit Options]
[CMake (Not 100% sure if CMake is necessary for this project or right)]
I also thought the way cv:: was being declared was strange for this:
namespace cv
{
using std::vector;
}
I apologize for the dumb question, I am brand new to both Qt and OpenCV

Qt adding library gstreamer-1.0

I am making a project, dependent on gstreamer-1.0, glib-2.0 and gobject-2.0.
Building in console and in VSCode works fine, but when i get to Qt, i receive the following error message:
:error: cannot find /usr/lib/x86_64-linux-gnu/: File format not recognized
My .pro file:
QT += core
QT -= gui
TARGET = Accord
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
working_directory.cpp \
player_core.cpp \
message.cpp
HEADERS += \
working_directory.h \
message.h \
player_core.h
CONFIG += link_pkgconfig \
c++11
PKGCONFIG += gstreamer-1.0 \
glib-2.0 \
gobject-2.0 \
gio-2.0
INCLUDEPATH += /usr/local/include/ \
/usr/include \
/usr/include/gstreamer-1.0 \
/usr/include/glib-2.0 \
/usr/lib/x86_64-linux-gnu/glib-2.0/include \
/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include
LIBS += /usr/lib/x86_64-linux-gnu/ -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 \
-lgio-2.0 \
With specified pkgconfig should be enough. You don't need to specify the libraries independently. This might be necessary in Windows, but not in Linux. I use the next variables in Linux (Ubuntu):
CONFIG += link_pkgconfig
PKGCONFIG += gstreamer-1.0 glib-2.0 gobject-2.0 gstreamer-app-1.0 gstreamer-pbutils-1.0
If your GStreamer is in the default location it should work.
I solved it by changing QMAKE_CFLAGS_ISYSTEM = -isystem
to QMAKE_CFLAGS_ISYSTEM = -I (can be added to .pro).
for Qt 5.10 +
I think that LIBS += /usr/lib/x86_64-linux-gnu/ is incorrect, hence the
error: cannot find /usr/lib/x86_64-linux-gnu/: File format not recognized.
You probably meant
LIBS += -L/usr/lib/x86_64-linux-gnu/
to add the directory to ld's search path (although that shouldn't be necessary).

Using Caffe in Qt Console Application

I am trying to use caffe in Qt IDE,
I have the following code:
#include <QCoreApplication>
#include "caffe/caffe.hpp"
using namespace caffe;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Caffe::set_mode(Caffe::CPU);
return a.exec();
}
I just wanted to set Caffe in CPU Mode.
I have the following .pro file
QT += core
QT -= gui
CONFIG += c++11
TARGET = CaffeTest_v0
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += /home/ahmet/caffe/include \
/home/ahmet/caffe/distribute/include \
/home/ahmet/caffe/build/lib
LIBS += -lcaffe
SOURCES += main.cpp
I have the following problem :
My problem is I want to set caffe in CPU mode, I installed caffe in CPU mode.
How can I set Caffe in CPU mode in main?
P.S. I believe I installed caffe corectly, because I tested by the following command in gnome terminal
caffe train -solver lenet_train_solver.prototxt
I also searched the following websites:
http://tzutalin.blogspot.co.uk/2015/05/caffe-on-ubuntu-eclipse-cc.html
Error while including Caffe in C++ Project using cmake
https://github.com/BVLC/caffe/issues/3317
https://groups.google.com/forum/#!topic/caffe-users/DAv5EcsvbIU
In .pro file, I should add
DEFINES += CPU_ONLY
solves the problem.
Final .pro file is below:
QT += core
QT -= gui
CONFIG += c++11
TARGET = CaffeTest_v0
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
DEFINES += CPU_ONLY
INCLUDEPATH += /home/ahmet/caffe/include \
/home/ahmet/src/caffe/proto \
/usr/include/boost
LIBS += -L/home/ahmet/caffe/build/lib \
-lcaffe \
-L/usr/lib/x86_64-linux-gnu \
-lboost_system
SOURCES += main.cpp

OpenCV with Qt: The program has unexpectedly finished

I am trying to configure OpenCV with Qt Creator 2.7.0 (Qt 5.0.2) on windows 8 64bit.
While executing my program, I get the following error:
The program has unexpectedly finished.
This is my main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
IplImage *image = cvLoadImage("E:\\lena.jpg"); //If this is removed, the program runs OK
return a.exec();
}
My .pro file is
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled1
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
unix:!mac {
message("* Using settings for Unix/Linux.")
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib/ \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc
}
## OpenCV settings for Mac OS X
macx {
message("* Using settings for Mac OS X.")
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib/ \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc
}
## OpenCV settings for Windows and OpenCV
win32 {
message("* Using settings for Windows.")
INCLUDEPATH += "C:\\OpenCV\\opencv\\build\\include" \
"C:\\OpenCV\\opencv\\build\\include\\opencv" \
"C:\\OpenCV\\opencv\\build\\include\\opencv2"
LIBS += -L"C:\\OpenCV\\opencv\\build\\x64\\mingw\\lib" \
-lopencv_core244 \
-lopencv_highgui244 \
-lopencv_imgproc244
}
Environment Variables are:
OPENCV_DIR:C:\OpenCV\opencv\build\x64\mingw Path:
G:\5.0.2\Tools\MinGW\bin;G:\Qt\5.0.2\mingw47_32\bin
What could be the problem ?
I suggest you use the OpenCV 2.x API if possible. The error handling is better.
This would be cv::Mat image = cv::imread("E:\lena.jpg");
If the image is empty, it means you have the wrong path.
Also, make sure the opencv dll are in the path of your executable (core, highgui and imgproc).
You might need to change
-lopencv_core244 \
-lopencv_highgui244 \
-lopencv_imgproc244
to
-lopencv_core244d \
-lopencv_highgui244d \
-lopencv_imgproc244d
note 'd' at the end of each lib (if you are to build in debug)
Have you solved the problem?
Have you tried adding system("PAUSE"); after the return a.exec(); ?
Just some extra notes:
Also try
try
{
...
}
catch (Exception e)
{
...
}
to see if you can find the error
thirdly, check the file permissions for lena.jpg
Lastly, see if you can use the path E:\lena.jpg