dlib and Qt: building errors - c++

I have installed dlib to have the static library in my computer and i want to use it in a Qt project but the problem is, once the dlib library is linked to my project i can build it and display simple matrix from dlib namespace but if i try to define a deep learning network i got the following error.
/home/jimmy/Desktop/Connected_Robotics_Watson/workco/work/mainWindow.cpp:-1: error: undefined reference to `dlib::cpu::pooling::pooling()'
i am really lost on how to use with Qt.
Here is my .pro file:
QT += network
QT += widgets
TEMPLATE = app
TARGET = Connected
INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui
-lopencv_imgcodecs -lopencv_videoio
QMAKE_CXXFLAGS += -std=c++11
PKGCONFIG = dlib-1
# Input
HEADERS += mainWindow.hpp
SOURCES += main.cpp mainWindow.cpp
If i use the library with normal cpp code and use a cmake to compile, evrything works well.
Does someone have an idea on this problem?

Related

How can I make OpenCV the default library for my qt projects?

Please suppose that I want to link OpenCV libraries in Qt-creator, in common, I will add headers usingINCLUDEPATH and link libraries using the LIBS variable, which is used in the qmake file but if we use OpenCV in most of our projects then we have to include OpenCV library every time, so is there any way to add opencv libraries automatically at the time of creating a project.
I use the below command to add OpenCV libraries for my projects every time.
INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and etc.
UPDATE
I will use the following headers for OpenCV4:
INCLUDEPATH += /usr/local/include/opencv4
1) You can create a .prf (project feature) file in your mkspecs/features directory:
/usr/share/qt5/mkspecs/features/opencv.prf
INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and another libraries
Now simply add CONFIG += opencv to your .pro file to have it working. Or you can even auto-enable this feature by editing mkspecs/qconfig.pri:
/usr/share/qt5/mkspecs/qconfig.pri
...
CONFIG += ... opencv
...
BTW. qconfig.pri is a part of qt_config, which is loaded by all QMake's machine-dependent specs, so it should always work. However, it's also possible to patch only a specific spec (for example, /usr/share/qt5/mkspecs/linux-g++/qmake.conf, or whatever is appropriate for your configuration). Of course, it's even possible to add all these INCLUDEPATH+=... and LIBS+=... straight into that qmake.conf and get rid of the .prf file completely.
2) Alternatively, if you don't want to pollute Qt installation, you can use manual include:
opencv.pri
INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and another libraries
myprogram.pro
include(path/to/opencv.pri)
...
When you installed opencv you must also install the opencv.pc file, this file can be used to make it simple, since Qt supports package.config, if so, it replaces what it shows by the following:
unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += opencv
Actually Qt Creator offers a simple way, you just have to right click on the name of your project and select the option Add Library:
Then you will get a dialog where you must select the type of library:
In this case I used the fourth option, and put the name of the library: opencv.
Then you press the next and finish buttons.

How to link to SDL2 libraries under Qt Creator

I have compiled the latest SDL2 libraries, obtained from the 'official' mercurial repository, and followed the instructions for the Ubuntu/Linux build.
But Qt creator fails to link the statically built libraries. Here's the qmake script:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
unix:!macx: LIBS += -L/usr/local/lib/libSDL2.a
INCLUDEPATH += /usr/local/include
SOURCES += main.cpp
The linker reports several undefined references, including SDL_Init.
You have to change your LIBS line to this:
LIBS += -L/usr/local/lib -lSDL2
as -L let you define the path where linker looks for libraries to link, while -l defines which library to link to. On Unix systems the library called ASD is represented by a libASD.so file (in this example .so is for shared library, in your case there is .a as it is static library).
EDIT:
I've prepared very simple main.cpp:
#include <SDL/SDL.h>
int main()
{
SDL_Init(SDL_INIT_VIDEO);
return 0;
}
build SDL 2.0.3 as static library with /usr/local prefix and I needed to add 2 other libraries to my .pro file to compile this. Here it is:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
CONFIG -= app_bundle
SOURCES += main.cpp
LIBS += -L/usr/local/lib -lSDL2 -ldl -lpthread
INCLUDES += /usr/local/include
And now it compiles flawlessly.

Qt Creator does not recognize the my change in the pro. file

When I include something in Qt Creator, later I find out that that include does not exist, I want to correct that mistake by using a right path, or just deleting the include. But, that did not work, even if I delete the wrong include, but Qt Creator still try to find that include in the next build/run. I have already try to rebuild/clean the project but that does not work either. The only solution was to create a new project, or place the included file in that "wrong" place. I thought this question should not be a difficult one. But I fail to solve it.
for example, this is my pro. file.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = simpleStitch
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:\opencv249\build\includes
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_core249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_highgui249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_features2d249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_imgproc249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_stitcher249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_calib3d249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_nonfree249.lib
I have make a mistake in the LIBS += C:\opencv249\build\x64\vc12\lib\opencv_stitcher249.lib.
the right one should be stitching249.lib.
after I correct it to be stitching249.lib. the qt still try to find the C:\opencv249\build\x64\vc12\lib\opencv_stitcher249.lib. it is pretty strange. qt does not recognize my change in the pro. file even if I use the clean/ rebuild.
Run qmake? if you make changes to the .pro file then you need to qmake again or it will just be building against whatever is there from your last qmake
Please give more information, so that we can understand specific problem. Here is what you need to do before starting a new project.
To add kits, select Tools > Options > Build & Run > Kits > Add.
Each kit consists of a set of values that define one environment, such as a device, compiler, and Qt version. If you know you have installed a Qt version, but it is not listed in Tools > Options > Build & Run > Qt Versions, you must add it.
Also check that your compiler is listed in Tools > Options > Build & Run > Compilers.
And also you should modify your .pro file in order to your settings. Here is one of my project's .pro file. You can modified it yourself...
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = myTarget
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib \
-lopencv_core \
-lopencv_imgproc \
-lopencv_highgui \
-lopencv_ml \
-lopencv_video \
-lopencv_features2d \
-lopencv_calib3d \
-lopencv_objdetect \
-lopencv_contrib \
-lopencv_legacy \
-lopencv_flann
Then, in your code you need to include which libraries you want to use.. Such as:
#include <QMainWindow>
#include <opencv/cv.h>
#include <opencv/highgui.h>
I have never used Windows. As I know in windows symbol \ occurs problem if you not use 2 of them. Here is an example to understand clearly..
INCLUDEPATH += D:\\ProgrammingTools\\opencv\\build\\include
CONFIG( debug, debug|release ) {
LIBS += -LD:\\ProgrammingTools\\opencv\\build\\x86\\vc10\\lib\
-lopencv_core246d\
-lopencv_highgui246d\
-lopencv_imgproc246d\
-lopencv_features2d246d\
}
else {
LIBS += -LD:\\ProgrammingTools\\opencv\\build\\x86\\vc10\\lib\
-lopencv_core246\
-lopencv_highgui246\
-lopencv_imgproc246\
-lopencv_features2d246\
}

OpenGL Ubuntu 13.10 QtCreator - undefined reference to `glutMainLoop`

If I try to execute the code from here, the OpenGLBook, I get this error messages:
undefined reference to glutMainLoop
undefined reference to glGetString
undefined reference to glClearColor
and so on ... I installed the following packages:
libglew-dev, liblglew1.8, freeglut3-dev and freeglut3.
I am running on Ubuntu 13.10 with Qt Creator v3.0.0.
My .pro file looks like this:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
Build step for debugging is qmake Project.pro -r -spec linux-g++ CONFIG += debug
How can I fix my project?
Had to change my pro file to
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
# this is the important part
unix|win32: LIBS += -lGLU
unix|win32: LIBS += -lGL
unix|win32: LIBS += -lglut
Welcome to c++ !
You are using a library (freeglut I gather) and for this you need 2 things :
1) include the headers (*.h file(s)) that declare the functions/classes/methods that you need
2) your program needs to link with the actual shared library (.so files in Linux)
In your .pro file you need to specify the path to the libraries you want to link with. Add this :
LIBS += -lglut
It means add the library glut to the list of libraries to link.

libgcc_s_sjlj-1.dll is missing in Qt 5.1

My program won't start, complaining that libgcc_s_sjlj-1.dll is needed. However, this file doesn't exist in Qt directory. I did some search and found that -static-libgcc and -static-libstdc++ should be added. So here is my .pro file:
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = mouseEventProcess
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
fileOp.cpp \
xmlpraser.cpp \
pixmapOp.cpp \
mathOp.cpp
HEADERS += mainwindow.h \
fileOp.h \
xmlpraser.h \
pixmapOp.h \
mathOp.h
FORMS += mainwindow.ui
#COMPILE LIBGCC_S_SJLJ-1.DLL AND LIBSTDC++-6.DLL INTO THE EXE FILE
win32{
QMAKE_LFLAGS += -static-libgcc
QMAKE_LFLAGS += -static-libstdc++
#BOOST LIBRARIES. CHANGE TO YOUR OWN.
INCLUDEPATH += D:/boost_1_51_0
#OPENCV LIBRARIES. CHANGE TO YOUR OWN.
INCLUDEPATH += D:/opencv2.4.4/include
INCLUDEPATH += D:/opencv2.4.4/release/install/include
LIBS += -LD:/opencv2.4.4/release/install/lib \
-lopencv_core244 \
-lopencv_highgui244 \
-lopencv_imgproc244
#-lopencv_features2d244 \
#-lopencv_calib3d244
}
unix{
#BOOST LIBRARIES. CHANGE TO YOUR OWN.
INCLUDEPATH += /home/panda/boost_1_51_0
#OPENCV LIBRARIES.IF YOU COMPILED AND INSALLED
#OPENCV FROM CMAKE & MINGW, JUST LEAVE IT BE,
#UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING.
INCLUDEPATH += /usr/local/include/opencv
INCLUDEPATH += /usr/local/include/opencv2
LIBS += -lopencv_core -lopencv_imgproc -lopencv_highgui
LIBS += -lopencv_ml -lopencv_video -lopencv_features2d
LIBS += -lopencv_calib3d -lopencv_objdetect -lopencv_contrib
LIBS += -lopencv_legacy -lopencv_flann
}
If this works, neither libgcc_s_sjlj-1.dll and libstdc++-6.dll is needed. However, the program still needs libstdc++-6.dll before I put it into .exe folder.
So my question is: Where can I get libgcc_s_sjlj-1.dll or is there any problem in my .pro file?
Bah, I am stupid. Your 'my program lacks libgcc_s_sjlj-1.dll, not libgcc_s_dw2-1.dll' should have rung a bell.
You compile with the wrong MinGW. There are several different exception handler for MinGW available: sjlj, dwarf, seh. Dwarf is 32bin only. When you have the libgcc_s_dw2-1.dll it means, you have a 32bit only MinGW installed.
You must compile your programs with the same MinGW, which was used to compile your Qt. The sjlj MinGW works for 32bit and 64bit so I suppose it makes sense that the qt-project provides binary packages, which were compiled with sjlj-MinGW.
There are some MinGW packages available, which allow you to choose, which exception handling mechanism you will use. Best choice is probably to use the MinGW, which is bundled in the Qt 5.1.1 installer packages.