Back to the past - using "bluez" library directly in QT
-
I have a project using QT Bluetooth API AFTER I added "Bluetooth" to QT
QT = core bluetooth widgets.Now I am trying to use "blueZ" directly, bypassing QT API and getting "undefined symbols l" .
( All the required #include(s) are OK "
Hence no access to "blueZ"Just for drill I did
sudo apt install bluezWhich confirms I have bluez installed - so the QT API is OK.
What else do I have to do to be able to use "blueZ" library direct ?
( Linux Ubuntu ) -
@AnneRanch said in Back to the past - using "bluez" library directly in QT:
Just for drill I did
sudo apt install bluezAs told you many times - if you want to use a library you have to install it's development package -> bluez-dev for example.
-
@Christian-Ehrlicher Would it be to forward to tell you - please do not respond .
I really do not need to be treated this childish way .BTW I did check
sudo apt-get install bluez libbluetooth-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
bluez is already the newest version (5.60-0ubuntu2.2).
libbluetooth-dev is already the newest version (5.60-0ubuntu2.2).
The following package was automatically installed and is no longer required:
libfwupdplugin1
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.OK, I know I have a Linux package - now how do I identify the actual bluetoothg.so file so I can use QTCreator to link to it ?
I assume it would be "system library".
-
Since you don't tell us which undefined symbols you have how should we know which library you're using and which you should use?
You should make sure you only have one bluez library installed and that the bluez headers you use match the bluez library you link to. But that's a normal task for every header and library you're using. -
@AnneRanch said in Back to the past - using "bluez" library directly in QT:
how do I identify the actual bluetooth.so file so I can use QTCreator to link to it ?
I can use QtCreator to link to it , but I do not know WHERE it is nor what is the actual name ,
-
@AnneRanch said in Back to the past - using "bluez" library directly in QT:
I can use QtCreator to link to it
QtCreator is an IDE, not a linker
but I do not know WHERE it is nor what is the actual name ,
When you link against 'bluetooth' the library must be named 'libbluetooth.so' (this schema is true for all unix libraries btw). If you don't install it by yourself it's for sure in /usr/lib or /usr/lib64 depending on your architecture.
-
@Christian-Ehrlicher said in Back to the past - using "bluez" library directly in QT:
find -name "blue.so"
Finds no libbluetooth.so .
What is my next step to solve this ?
(And why does QT bluetooth API works ? )
PS
QtCreator is an IDE, not a linker
I really do not care for this irrelevant remark - you may as well call it "banana".,
... and why you need to know WHAT is failing if I am asking how to link to "blueZ' library?
-
@AnneRanch said in Back to the past - using "bluez" library directly in QT:
find -name "blue.so"
Finds no libbluetooth.so .It would be rather surprising if it did ... :D
QtCreator is an IDE, not a linker
I really do not care for this irrelevant remark - you may as well call it "banana".,
It's not irrelevant - it's important to understand what's going wrong. But I know you don't care why something is going wrong.
-
I have used QT (IDE if you insist ) and added "package library " "bluez".
however, i AM STILL GETTING RUN TIME ERRORS - MISSING
hci_get_routeBUT
hci_open_dev passes OK.
So it seems to be a "blueZ" issue now .
What I do not understand -
why this error does no show during compile or linking ?
( Perhaps because QT is IDE ?)or because the project is a library ?
My compiler is noi hapoopy , but it allways was,
-
@AnneRanch said in Back to the past - using "bluez" library directly in QT:
Your screen shot does not not show an error, it is a warning. This is your compiler trying to protect you from common mistakes.
It is telling you that dev_id is used before it has had any value set. In your case this is because you have commented out the line (95) that sets dev_id's value and dev_id is not set previous to that.however, i AM STILL GETTING RUN TIME ERRORS - MISSING
hci_get_routeAbsent the actual error message, my best guess is that:
This is not a compilation error. Your code compiles with warnings.
This is a linker error. Your code fails to link because it finds no library containing a function "hci_get_route"
This is not a run time error: you have to have a linked executable to be able to run anything.The linker cannot file the bluez library because it is either:
- Not listed as a library to link on the linker command line. This would be the '-l' (lower case L) option for the GNU tools on Linux (e.g. -lbluetooth).
- The named library does not appear in the default locations or in a location passed to the linker on its command line. These would be the '-L' options. There may be none of these for a typical install of a system packaged library.
If the result of
locate libbluetooth.so
is empty then the library is not present at all.Both of these options to the linker are driven by the LIBS variable in your qmake project file. We cannot see what you have here so your next course of action is to:
- Copy and paste the entire text surrounding the linker error including the command (ld ...) make executed. You can see the in the compiler output tab if you are using Qt Creator. Do not paraphrase it. Do not only post the error message.
- Post the entire text of the INCLUDEPATH and LIBS variables in the your qmake project file.
-
@ChrisW67 Part of the problem is solved. Would you be willing to further discuss this post FOR LEARNING purpose only ?
I am willing, but will not waste my time with "I told you so " attitude and explanations on how the world was created ."just the facts ma'am..."
-
People in the thread have been trying to discuss some facts and help with education.
Here is some further education.
The <bluetooth/bluetooth.h> includes, and the corresponding library link, libbluetooth.so, for Linux Bluetooth development are part of the Ubuntu libbluetooth-dev package.
A very simple example program is (basic C code from here):
#include <QCoreApplication> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/socket.h> #include <bluetooth/bluetooth.h> #include <bluetooth/hci.h> #include <bluetooth/hci_lib.h> int main(int argc, char **argv) { QCoreApplication app(argc, argv); inquiry_info *ii = NULL; int max_rsp, num_rsp; int dev_id, sock, len, flags; int i; char addr[19] = { 0 }; char name[248] = { 0 }; dev_id = hci_get_route(NULL); sock = hci_open_dev( dev_id ); if (dev_id < 0 || sock < 0) { perror("opening socket"); exit(1); } len = 8; max_rsp = 255; flags = IREQ_CACHE_FLUSH; ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info)); num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags); if( num_rsp < 0 ) perror("hci_inquiry"); for (i = 0; i < num_rsp; i++) { ba2str(&(ii+i)->bdaddr, addr); memset(name, 0, sizeof(name)); if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "[unknown]"); printf("%s %s\n", addr, name); } free( ii ); close( sock ); return 0; }
and a minimal Qt project file (test.pro) that will compile and link it:
TEMPLATE = app TARGET = test INCLUDEPATH += . SOURCES += main.cpp LIBS += -lbluetooth
The libbluetooth-dev package puts everything in standard paths so:
- No need to add search locations to INCLUDEPATH so the compiler can find the header files
- No need to add search locations to LIBS with -L options
The only thing required to link is the name of a library to connect with the application, in this case the bluetooth library identified in the LIBS variable
-lbluetooth
.For libraries in Linux there is often a pkg-config file that can be queried (it is confusingly named in this case):
# Things you may need to add the INCLUDEPATH or CFLAGS (for the compiler) $ pkg-config --cflags bluez # Things you need to consider for LIBS (for the linker) $ pkg-config --libs bluez -lbluetooth
You can even ask Qt to use pkg-config directly to set INCLUDEPATH and LIBS internally:
TEMPLATE = app TARGET = test INCLUDEPATH += . SOURCES += main.cpp CONFIG += link_pkgconfig PKGCONFIG += bluez