QtCreator and OpenCV - c++

I managed to compile successfuly programs that use OpenCV with QtCreator but i have a problem with the dlls when i try to execute my application.
This is the error i get. The wierd thing is that i don't have this dll in my system.
I tried to download it and place it in the same directory with the executable but i get the same error.
here is my .pro file
LIBS += -Lc:/Users/Libraries/OpenCV2.3/build/x86/mingw/bin/
LIBS += -lopencv_calib3d230 \
-lopencv_contrib230\
-lopencv_core230 \
-lopencv_features2d230 \
-lopencv_flann230 \
-lopencv_gpu230 \
-lopencv_highgui230 \
-lopencv_imgproc230 \
-lopencv_legacy230 \
-lopencv_ml230 \
-lopencv_objdetect230 \
-lopencv_video230
INCLUDEPATH += c:/Users/Libraries/OpenCV2.3/build/include/
SOURCES += \
main.cpp
Anyone that knows why this problem occurs?

I found what was going wrong.
I compiled opencv again and changed my .pro file to link from that folder.
Linking with the opencv-superpack package that is provided for windows caused this problem.
I hope this will help others facing the same problem.

Did you try, instead of simply putting the dll in the folder to add it to the path of your system ?
On win XP it's something like:
Configuration Panel > System > Advanced > Paths

Downloading a versioned DLL probably won't work. libstdc++-6.dll should be in the bin directory of your MinGW installation (which was probably included with QtCreator, check there).
You must distribute this dll with your app (or link with -static) or at least add its directory to PATH.

Related

qt 5 looking for API-MS-WINxx.dll using GDAL headers

I am developing a C++ Software with OpenCV 3.1 and QT 5 under win7 64Bit System.
The uses compiler is the VS2010 32bit.
I have to use another lib, called GDAL. I built this lib, set PATH environment and set the project properties in QT. As soon as I include a single .h file of GDAL the developed program starts and the instantly ends. QT gives messages like “debugging started” “debugging ended”.
Set break points won’t be reached so the program isn’t even starting. The GDAL lib seems to be included correctly because the used GDAL variables and classes are indicated by the autocomplete function of QT.
I used dependency walker to see if some dll are not loaded. This tools tells me that the following dlls are missing. These dll don’t exist on the harddrive.
API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL
API-MS-WIN-CORE-COM-L1-1-1.DLL
API-MS-WIN-CORE-DEBUG-L1-1-1.DLL
API-MS-WIN-CORE-DELAYLOAD-L1-1-1.DLL
API-MS-WIN-CORE-ERRORHANDLING-L1-1-1.DLL
API-MS-WIN-CORE-FILE-L1-2-1.DLL
API-MS-WIN-CORE-FILE-L2-1-1.DLL
API-MS-WIN-CORE-HEAP-L1-2-0.DLL
API-MS-WIN-CORE-HEAP-OBSOLETE-L1-1-0.DLL
API-MS-WIN-CORE-JOB-L2-1-0.DLL
API-MS-WIN-CORE-KERNEL32-LEGACY-L1-1-1.DLL
API-MS-WIN-CORE-LIBRARYLOADER-L1-2-0.DLL
API-MS-WIN-CORE-LOCALIZATION-L1-2-1.DLL
API-MS-WIN-CORE-LOCALIZATION-OBSOLETE-L1-2-0.DLL`enter code here`
One dll called GPSVC.dll was downloaded from the web. I have read several threads that people have same issues. Some have been fixing these issues by installing redistributable packages. I have all available redistributable packages installed and VS2010 ultimate.
I am getting sick of this problem, does anyone have THE solution to fix? What programs are associated with these listed dlls.
Would downgrading of QT 5 to QT 4 solve the problem.
I haven’t found threads with these issues when QT 4 is used.
Any suggestions are welcome!
Thanks
edit:
just to make all this clear, I would like to give you an overview of my settings.
the windows Path variable looks like this:
E:\opencv31\build\install\x86\vc10\bin;
C:\Qt5\5.5\msvc2010\bin;
E:\GDAL\bin
the .pro file of the qt project:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = AirportExtractor
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
imageanalyzer.cpp \
airport.cpp \
filterslider.cpp \
framewindows.cpp \
scribblearea.cpp \
HEADERS += mainwindow.h \
imageanalyzer.h \
airport.h \
filterslider.h \
framewindows.h \
scribblearea.h \
FORMS += mainwindow.ui \
filterslider.ui \
framewindows.ui \
INCLUDEPATH += E:/GDAL/include/
INCLUDEPATH += E:/opencv31/build/install/include/
LIBS += -LE:/opencv31/build/install/x86/vc10/lib -lopencv_calib3d310d \
-LE:/GDAL/lib -lgdal_i \
I added the following paths to the project settings:
INCLUDE E:\GDAL\include;
LIB E:\GDAL\lib;

Adding libraries to project

I'm new to Qt, and got following error to my C++ project:
fatal error: apr_pools.h: No such file or directory
I installed apr from https://apr.apache.org/compiling_unix.html and compiled it by executing:
./configure
make
make install
But I have no idea now how to link proper files to my project.
I solved my problem by adding external library. The result in .pro file is as below:
unix:!macx: LIBS += -L/usr/local/apr/lib/ -lapr-1
INCLUDEPATH += /usr/local/apr/include/apr-1
DEPENDPATH += /usr/local/apr/include/apr-1
But anyway thanks everyone for their time and good intentions :)
You must:
Specity in your .pro where header files must be searched: something like win32:INCLUDEPATH += "C:/mylibs/extra headers"
unix:INCLUDEPATH += "/home/user/extra headers"
You must specify which library must to be linked: something like
win32:LIBS += /mylibs/lib.so
unix:LIBS += c:/mylibs/library
This is not about linking but about preprocessing for now. (the preprocessor = the program or part of the compiler which read all the lines beginning with a '#' and replace macro and insert included headers.)
The preprocessor can't find your header
see http://qt-project.org/doc/qt-5/qmake-project-files.html#declaring-other-libraries
you have to add an include path to where your additional headers are.
[EDIT]
But there are no packages in your distribution ?
What is you OS, or linux distribution ?
if you want to install the bins and headers, maybe something like ./configure --prefix=/usr ; sudo make install should be needed or copy the files directly (adapt to your system and for the makefile)
[/EDIT]

Adding .so lib into .pro file in eclipse. C++ / Eclipse / Linux

Im working on app (C++ / QT / Eclipse Helios) which allows to connect to database. On some distributions of Linux (SUSE) there is a problem with libraries. 'error while loading shared libraries: libldap-2.4.so.2: cannot open shared object file: No such file or directory' Is there a possibility to add those libs into app build? I tried adding them into .pro file
FORMS +=
linux-g++{
INCLUDEPATH += source/include
LIBS += source/libldap-2.4.so.2 \
source/libldap_r-2.4.so.2 \
source/libldif-2.4.so.2 \
but it doesn't work at all.
Any ideas?
Well, installing libs on SUSE was not an option. I resolved that problem using small bash script
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DIR/lib
./myprog
and I put missing libs in folder /lib. Only inconvenience is that you have to run app using this script, not clicking the app itself. Anyway, thanks for the response! :)

QtCreator unable to find Qxt headers on Linux?

I'm working on a Qt5/QtQuick/QML application that's supposed to use QxtGlobalShortcut for hotkey control when the application is hidden or out of focus. I've been developing it using QtCreator on Linux, and I'm not entirely familiar with Linux development so I may have missed something simple.
First off, I tried cloning the master branch of the Qxt git repo from here. But for some reason ./configure failed to create a makefile according to an error that I was getting from make and make install. I'm not very experienced in building other people's projects/libraries from source, and the output I was getting from ./configure wasn't specific enough for me to figure out what was going on..
So instead, I decided to grab libqxt-dev from (X)ubuntu's APT repo. After it finished installing I added these lines to the bottom of my QtCreator project file:
INCLUDEPATH = usr/include
CONFIG += qxt
QXT += core gui
After setting up a basic global shortcut based totally off the Qxt documentation's example. I got a few compilation errors. First of all, the Qxt seem to use:
#include <QxtGlobalShortcut>
But QtCreator couldn't find that file, so I changed it to this:
#include <qxt/QxtGui/QxtGlobalShortcut>
Now it could find the Global Shortcut class header, and QtCreator stopped grumbling at me. Unfortunately, upon compilation QtCreator shot out this error message:
/usr/include/qxt/QxtGui/qxtglobalshortcut.h:28: error: qxtglobal.h: No such file or directory
I think this is caused by a problem in my project's INCLUDE path or something, but even having tried changing my projects INCLUDE path to this:
INCLUDEPATH = usr/include
usr/include/qxt/QxtCore
usr/include/qxt/QxtGui
CONFIG += qxt
QXT += core gui
I still get the same error message that QxtGlobal.h (which is being #included in QxtGlobalShortcut.h) can't be found..
So, I'm really not sure what I've done wrong, and I'm out of ideas about how to fix this.
Hopefully someone can help me understand what step I've skipped so that I can continue coding! Thanks!
EDIT: Here's what I have for my entire Qt project .pro file:
TEMPLATE = app
QT += qml quick
SOURCES += main.cpp \
Gamepad.cpp \
Script.cpp \
System.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
HEADERS += \
Gamepad.h \
Script.h \
System.h
LIBS += -L/usr/lib -lSDL2
CONFIG += qxt
QXT += core gui
Everything before LIBS was automatically generated by QtCreator for my project. I added the LIBS, CONFIG, and QXT elements as per the user instructions for SDL2 and Qxt.
This is a big problem here:
INCLUDEPATH = usr/include
1) You are using relative path from the current working directory, so not /usr/include from the root of the filesystem.
2) You are deleting everything in the INCLUDEPATH because you set rather than append with +=.
3) It is unnecessary to add that line anyway since /usr/include will be looked up by default.
4) Even if it was not, you have #include "qxtglobal.h" instead of #include <qxtglobal.h>.
I would suggest to delete that line and then it should just work.

Build a 3rd party library from source within an existing Qt project

My project requires a version of zlib that isn't present on all target machines, so I want to build zlib from source in my project. Then when I make my project, it should first build zlib so it can be linked to when compiling my project.
One complication is that zlib requires configure to be run before make can be run.
I'm not even sure where to start here. Is there functionality built in to Qt Creator for importing 3rd party library source code like this, or do I need to code out a custom .pro file?
I tried the "Add Library..." menu that appears when right-clicking on my project, but it doesn't recognize the library - likely because no .pro file exists. I also tried to create a .pro file by File -> New Project -> Import Existing Project, and it's able to compile zlib once configure has been run, but it still doesn't generate a .pro file.
I thought that maybe the subdirs might be useful, but I'm not sure if that is the right route in this situation, and even if it is I am not sure whether I can auto-create the necessary .pro file, or I have to create it myself.
Given the source code for a 3rd party library like zlib, how do I integrate that into an existing Qt project such that I can compile the library from source, and use it in my project?
Yes, you need to create a project file for it. You can find my version below what I used for several projects.
zlib.pro
QT -= core gui
TARGET = zlib
TEMPLATE = lib
# Use this for static zlib rather than the default dynamic
# CONFIG += staticlib
include(zlib.pri)
zlib.pri
HEADERS += \
$$PWD/crc32.h \
$$PWD/deflate.h \
$$PWD/gzguts.h \
$$PWD/inffast.h \
$$PWD/inffixed.h \
$$PWD/inflate.h \
$$PWD/inftrees.h \
$$PWD/trees.h \
$$PWD/zconf.h \
$$PWD/zlib.h \
$$PWD/zutil.h
SOURCES += \
$$PWD/adler32.c \
$$PWD/compress.c \
$$PWD/crc32.c \
$$PWD/deflate.c \
$$PWD/gzclose.c \
$$PWD/gzlib.c \
$$PWD/gzread.c \
$$PWD/gzwrite.c \
$$PWD/infback.c \
$$PWD/inffast.c \
$$PWD/inflate.c \
$$PWD/inftrees.c \
$$PWD/trees.c \
$$PWD/uncompr.c \
$$PWD/zutil.c
INCLUDEPATH += $$PWD
Then in the project file including this one, you can do something like this:
main.pro
# CONFIG += order # If you wanna make sure about order. This is optional.
SUBDIRS += \
zlib \
...
If you wanna go even a bit more advanced with qmake, you can do something like this:
SUBDIRS += \
src_zlib \
src_mylib \
...
src_zlib.subdir = $$PWD/zlib
src_zlib.target = sub-zlib
src_zlib.depends =
src_mylib.subdir = $$PWD/mylib
src_mylib.target = sub-mylib
src_mylib.depends = src_zlib
As you can see this way, you would have a lot more reasonable control among the dependencies regardless the order set. For instance, you could still keep the entries in alphabetical order which is helpful with proper maintenance in the long run.
Then, you will need a line like this in the project file (.pro) of your subproject, let us say "foo", which depends on zlib.
foo.pro
LIBS += -L$${PROJECTROOT}/$${SUBDIR_TO_ZLIB} -lz
# These lines are only option, and you do not necessarily need them.
# win32:LIBNAME = zlib.dll
# unix:LIBNAME = libzlib.so
# PRE_TARGETDEPS += $${PROJECTROOT}/$${BUILD_SUBDIR_LIBS}/$${LIBNAME}
Following are instructions for adding a 3rd party repository to your Qt project and building it from source.
Some are able to add such libraries via Qt Creator, but I could never get that to work. So these are instructions on how to create the necessary .pro and .pri files instead. In this post, I will use zlib as an example, although other libraries should be similar.
Setup Build Order
Since your application depends on this library, we need to ensure that the library is built first. To do this, the 3rd party library and the source code for your application should be in sibling directories.
~/myApp $ ls myApp
src zlib
You probably already have a myApp.pro file that correctly builds your application. I recommend renaming it to src.pro, and you'll see why in the next step.
mv src/myApp.pro src/src.pro
Now you can create a new myApp.pro in the root directory.
~/myApp $ touch myApp.pro
~/myApp $ ls
myApp.pro src zlib
This is a rather simple .pro file that merely says "build zlib before myApp."
# ~/myApp/myApp.pro
TEMPLATE = subdirs
CONFIG += ordered # This tells Qt to compile the following SUBDIRS in order
SUBDIRS = zlib src
Create Library .pro File
Now we need to tell Qt how to build our 3rd party library. We do this by creating a new .pro file:
# ~/myApp/zlib/zlib.pro
TARGET = z # The name of the output library - can be whatever you want
TEMPLATE = lib # Tells Qt that we are compiling a library so the output will be bundled into a .a or .so file
CONFIG += staticlib # Tells Qt that we want a static library, so a .a file. Remove this and you will get a .so file
QMAKE_CFLAGS_WARN_ON -= -Wall # Optional - disable warnings when compiling this library
QMAKE_CXXFLAGS_WARN_ON -= -Wall # Optional - disable warnings when compiling this library
HEADERS += \
crc32.h \
deflate.h \
gzguts.h \
inffast.h \
inffixed.h \
inflate.h \
inftrees.h \
trees.h \
zconf.h \
zlib.h \
zutil.h
SOURCES += \
adler32.c \
compress.c \
crc32.c \
deflate.c \
gzclose.c \
gzlib.c \
gzread.c \
gzwrite.c \
infback.c \
inffast.c \
inflate.c \
inftrees.c \
trees.c \
uncompr.c \
zutil.c
If you are building something other than zlib, just change TARGET to the name of the library, and replace the contents of HEADERS and SOURCES with the files that need to be compiled for your library.
You can go ahead now and test out this .pro file.
~/myApp/zlib/ $ qmake
~/myApp/zlib/ $ make
...
~/myApp/zlib/ $ ls libz.a
libz.a
Yay!
Link The Library Into Your Application
Finally, we need to update the .pro file of your application to link in the 3rd party library. There are two parts to this:
Add library header files to your include path so the compiler can get the defined symbols from there.
Link the static (or shared) library during compile and linking time so the applicable object code can get linked into your application.
First, we'll add the header files into the include path. Add this line to src.pro.
INCLUDEPATH += zlib
This allows you to reference zlib.h in your code like so:
#include "zlib.h"
Otherwise, you would have to specify the full relative path of the header like this:
#include "zlib/zlib.h"
If you're fine with the second method, then there should be no need to update the INCLUDEPATH variable.
Second, we need to add the arguments the linker needs to find the static (or shared) library itself. Add this line to src.pro.
LIBS += -L$$PWD/../zlib -lz
The first part (-L$$PWD/../zlib) says that the folder containing the library is at ../zlib, which should be correct since zlib is a sibling folder to src. The second part (-lz) says that the name of the library is z. The linker infers from this that the library is actually located in the file libz.a.
Done
At this point, you may have to clean your build by doing a make distclean. But from there you should be able to build your project with the 3rd party library included by going to your base directory and running qmake and make.
cd ~/myApp
qmake -r
make
Note: Big thanks go to #LaszloPapp for getting this process started. Much of the source material for this answer came from his answer.
Alternatively if you are using QT Creator you could try to investigate "Project Settings" -> "Add Build Step" -> "Custom build step" and add script file there.
This could help to build lib before and then you just need to link it to your project.
I'm not sure, but most likelly you could pass the compilers settings like an argument to this script. I'm triing to solve it right now.