I am looking to edit and recompile the hcitool.c of bluez version 5.31. I installed the bluez 5.31 by following the procedure from the answer of this: Bluetooth Low Energy in C – using Bluez to create a GATT server
In my trial, I duplicated the hcitool.c file and named it as myhcitool.c inside the tools folder and I use the command
gcc -o myhcitool.o myhcitool.c.
This gives me an error
myhcitool.c:43:27: fatal error: lib/bluetooth.h: No such file or directory #include "lib/bluetooth.h" ^ compilation terminated.
I tried copying the myhcitool.c outside the tools folder and compile it there. That gave me a bunch of errors something like this:
/tmp/ccj1QmZK.o: In function `dev_info': myhcitool.c:(.text+0x293): undefined reference to `ba2str' /tmp/ccj1QmZK.o: In function `conn_list': myhcitool.c:(.text+0x501): undefined reference to `ba2str' myhcitool.c:(.text+0x50f): undefined reference to `hci_lmtostr' myhcitool.c:(.text+0x586): undefined reference to `bt_free' /tmp/ccj1QmZK.o: In function `cmd_dev':
I also tried editing the hcitool.c itself by modifying a simple printf in there and then redo the ‘make’ and ‘make install’ commands for the whole bluez. After that, when I tried running the hcitool, the modification that I did has no effect.
Advertisement
Answer
The compilation errors clearly state that you are missing files and directories and that there are undefined references to types (since you are missing the files). You are copying a file outside of its directory and trying to compile it. This won’t work as the includes (and more) required for it to compile correctly are missing.
If you want to edit hcitool directly you should download the Bluez source, unpack it,
cd
into it and./configure
it. The makefile will be generated and you can usemake
to build the executables. If you make change to the hcitool.c file you should make sure you recompile it and are running it inside the directory as./hcitool
and not as generalhcitool
as this runs the executable installed to your system, rather than the one you edited.If you want to build it outside of the Bluez directory as a sort of standalone, you will have to copy all the files and folders defined in the
#include <x>
statements that are needed and make a separate makefile for those, since copying the existing one will probably not work.If you want to add a new file to the Bluez source, make sure you also make the correct Makefile edits so that it is included during compilation.
I’d like to add that hcitool
has not been maintained for a long time and is on its way to being phased out of Bluez, so maybe you should take a different approach altogether!