PDA

View Full Version : including external library or package to Qt



user03
25th August 2016, 17:32
I downloaded the following package : https://github.com/labapart/gattlib for discovery of BLE device, I could discover the devices using the commands specified on the link, however, now I want to use this code to develop my own application. I tried implementing this on Qt. I copied the BLE scan code in a .c file and below is my .pro file:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
QT += BluezQt
SOURCES += \
ble_scan.c
packagesExist(glib-2.0) {
CONFIG += link_pkgconfig
PKGCONFIG += glib-2.0
}

LIBS += -pthread
LIBS += -lbluetooth
LIBS += -L/gattlib_0.2_x86_64/lib/pkgconfig
HEADERS += \
gattlib.h

However, I keep on getting following errors:
undefined reference to ''gattlib_connect'
and other functions which are defined in gattlib.

I think this has something to do with the package, could anyone please guide me on how to include this in Qt project. (I tried using cmake instead of qmake but it doesn't give any .pro file to add glib and bluetooth library, hence couldn't use it)

d_stranz
26th August 2016, 00:19
undefined reference to ''gattlib_connect'

This sounds like a compile-time error, not a link error. You have probably not added the proper #include to your source files for the headers for your library. It isn't enough just to add the header name to the .pro file.

You will probably end up with link errors as well, because your LIBS doesn't contain the name of the library to link to; you have only specified the directory it lives in.

user03
26th August 2016, 00:56
In the code #include statement for gattlib.h is present, I simply copied the following code: https://github.com/labapart/gattlib/blob/master/examples/ble_scan/ble_scan.c
Initially, I was getting compile time error for hci_le_set_scan_parameter and other functions which are a part of lbluetooth library, however, after including the same, i stopped getting error for the same. But I am not sure about how should I include the library in this case.

d_stranz
26th August 2016, 15:45
But I am not sure about how should I include the library in this case.

The same way you include the other libraries:

LIBS += -lgattlib (or whatever it is called).