4

This is a stupid question. But I cannot find a solution to it. I am trying to build a BLE application with reference to this tutorial https://people.csail.mit.edu/albert/bluez-intro/c404.html. I am cross-compiling for Raspberry Pi3 from my Windows pc wsl. I have downloaded the toolchain from https://github.com/raspberrypi/tools. And I have verified the toolchain by compiling a simple HelloWorld application and ran it from RaspberryPi. Now when I try to compile the above code I am getting the error

/mnt/c/Study/RaspberryPi/main.c:5:33: fatal error: bluetooth/bluetooth.h: No such file or directory
 #include <bluetooth/bluetooth.h>

I understand that Bluetooth.h is not my system. My question is where can I get it? So that I can cross-compile from windows. Do I have to download sdk for it? if needed where can I get it?

0
6

You can use Debian's (which is the distro Raspberry Pi OS is based on) search engine to locate any file:

enter image description here

Once you find the package containing the necessary files, you can install the same package on a Pi with apt-get, or download it manually from http://archive.raspbian.org/. You can also grab the Debian package directly from the search results, but beware that some packages in the Pi OS have subtle differences with their Debian counterparts.

If you need to get the files from a package without installing it, download it and extract the files you need with ar command or 7zip.

5

Not a stupid question at all. I couldn't immediately find a good explanation of how to install packages from source. However, some trial-and-error yielded this solution:

$ apt-cache search bluez

Yielded a list of suspects, one of which was:

libbluetooth-dev - Development files for using the BlueZ Linux Bluetooth library

Which looked like a reasonable choice.

$ sudo apt-get install libbluetooth-dev
...
The following additional packages will be installed:
  libbluetooth3
The following NEW packages will be installed:
  libbluetooth-dev libbluetooth3  

Afterwards, the code in the tutorial compiles and runs:

$ gcc -o simplescan simplescan.c -lbluetooth  
$ ./simplescan
CC:6D:A0:64:36:32  Roku Player. 

Which is a correct answer here in my flat. However it's not the complete answer as other BT-equipped devices (e.g. my iPhone) are laying about.

NOTES:

  1. Be sure to update & upgrade your system before installing new packages!
  2. Dmitry's answer - using Debian's search engine - is a better answer for the OP's question. It seems to me there may still be some guesswork involved, but it definitely helps narrow the field.
  3. For those that want to build and install packages from source natively, it seems there are apt options to support that.
2
  • This answer is useful when we compile the application for the host system for example compiling for x86 on x86, arm64 on arm64. But it doesn't work out if we are going to do cross-compilation for example arm64 on x86. apt install download only for the host system. Dec 19 '20 at 3:53
  • 1
    @SadaananthAnbucheliyan: You're correct. I didn't immediately catch the reference to cross-compiling, but the question was interesting to me because it wouldn't compile on my RPi either. I found how to correct this on RPi, and posted my answer. Only after reading Dmitry's answer did I realize my oversight: "cross-compile". I decided to leave my answer as it may be useful to others, but I've made a few edits to explain myself. You asked a good question - we don't get enough of those here :)
    – Seamus
    Dec 19 '20 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.