QT, undefined reference to `alpr::Alpr::~Alpr()' - c++

I am trying to run OpenALPR on QT. I installed it here. I can test it from terminal successfully. I got the error in the title on QT. Undefined reference error is caused by unlinked library but I add the libopenalpr.so under the path /usr/lib to the .pro file. Why I get that error?
My cpp file:
#include "alpr.h"
int main()
{
alpr::Alpr openalpr("us", "etc/openalpr/openalpr.conf");
}
My pro file:
QT += core
QT -= gui
TARGET = OpenAlprTry
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
LIBS += -L -lopenalpr

You can use pkg-config to link with your wanted library.
Add to .pro file:
unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += openalpr
Package name could be different or you could need to add more packages.
To check pkg-config names type in your terminal:
pkg-config --list-all | grep openalpr
and add packages like that
unix: PKGCONFIG += package1 package2 package3

Can you first check whether openalpr library is in the library path? IF not add the library path to the .pro file.

Related

QT 5.7 - google/protobuf file not found - include PATH error

I am trying to use google protobuf 2.6 in QT 5.7 (clang 7.0) with QT creator 4.0.3 on OSX without much luck.
The .pro file has
LIBS += `pkg-config --cflags -- libs protobuf`
to include the protobuf library.
In the header file I generated using my proto file contains the line
#include <google/protobuf/stubs/common.h>
this produces a compiler error of
error: 'google/protobuf/stubs/common.h' file not found
The protobuf package is found by QT with the LIBS += command in the pro file and I have the unfound header files in
/Users/<username>/Qt/5.7/Src/qtwebengine/src/3rdparty/chromium/third_party/protobuf/src/google/protobuf/stubs
and
/usr/local/include/google/protobuf/stubs/common.h
I installed protobuf using macports.
The header file autocompletes so QT knows where it is so I am not sure how to deal with the file not found error.
Any help much appreciated.
Thanks,
a.
edit:
I think the problem is /usr/local/ not being included is qt path, thus I can find the protobuf package but not any of the header files (even though it autocompletes?). How do I add to PATH in QT with el capitain?
edit 2:
Project file
#-------------------------------------------------
#
# Project created by QtCreator 2016-07-13T12:13:47
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testexample
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
../../../protobuf/message.pb.cc
QT_CONFIG -= no-pkg-config
HEADERS += mainwindow.h \
../../../protobuf/message.pb.h
FORMS += mainwindow.ui
RESOURCES += \
resources.qrc
LIBS += `pkg-config --cflags -- libs protobuf`
Using Protobuf 2.4 with Qt 5.7 in Windows/Linux/Mac. Download and compile Protobuf 2.4 with the compiler you are using, (Im using MSVC/MinGW on Windows, gcc in Linux, clan on Mac OS). And edit your .pro file. My .pro configuration using this steps:
Load the compiled library for debug/release mode:
#For Windows
win32 {
CONFIG(debug, release|debug) {
win32:LIBS += -llibprotobuf-debug
} else {
win32:LIBS += -llibprotobuf
}
}
#For linux
!win32:LIBS += -lprotobuf
Include the path with all protobuf source code:
win32:INCLUDEPATH += "..\\...\\directoty_protobuf\\src"
Its working fine for me.

Path not found in .pro file in Qt

In my .pro file in Qt project, I have used these two lines for adding necessary LIBS.
LIBS += -L "../../lib/bin/libname.a"
LIBS += -L "../../rfm2g/winver/libname.lib"
error: ../../rfm2g/winver/libname.lib: No such file or directory
The compiler found the file libname.a, but could not find the libname.lib, although the relative path for both files is correct. Does anybody have an idea?
The -L option wants a directory for -l to search, not the path to the actual library.
So you should either write e.g.
LIBS += -L../../lib/bin -lname
LIBS += -L../../rfm2g/winver -lothername
Or link with them directly
LIBS += ../../lib/libname.a
LIBS += ../../rfm2g/winver/libname.lib
Also make sure that the paths actually are correct. If you change to the build directory, and try to list the files (using ls or dir depending on platform) using the paths you have, can you list both files?

link boost libs to qt with msvc

I have installed qt-opensource-windows-x86-msvc2013_64_opengl-5.4.0.exe and compiled boost_1_58_0.zip with this command: b2 toolset=msvc --build-type=complete stage. It works fine with Visual Studio, but when I try use it with Qt I get this error:
:-1: error: LNK1104: cannot open file 'libboost_filesystem-vc120-mt-gd-1_58.lib'
Here is my .pro file:
TEMPLATE = app
QT += qml quick widgets
SOURCES += main.cpp \
testclass.cpp
RESOURCES += qml.qrc
INCLUDEPATH += C:\boost
LIBS += "-LC:\boost\stage\lib\libboost_filesystem-vc120-mt-gd-1_58.lib"
#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 += \
testclass.h
In the LIBS variable use just "-L" for correct library path (-L). You made a mix, specifying a file (lowercase l) while libs directory is missing.
You do not need to specify the library, boost has pragmas for that.

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.

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.