On Ubuntu 14.04, I'm trying to do a small example of bluetooth device listing but I'm facing a simple issue about linking with the bluetooth shared library when compiling this minimalistic demo http://people.csail.mit.edu/albert/bluez-intro/c404.html:
$ sudo apt-get install libbluetooth-dev
$ gcc -lbluetooth simplescan.c -o simplescan
/tmp/ccuwRsB5.o: In function `main':
simplescan.c:(.text+0x79): undefined reference to `hci_get_route'
simplescan.c:(.text+0x8c): undefined reference to `hci_open_dev'
simplescan.c:(.text+0x132): undefined reference to `hci_inquiry'
simplescan.c:(.text+0x18f): undefined reference to `ba2str'
simplescan.c:(.text+0x1f0): undefined reference to `hci_read_remote_name'
collect2: error: ld returned 1 exit status
$ nm -D /usr/lib/x86_64-linux-gnu/libbluetooth.so.3.13.0 | grep hci_get_route
0000000000008f00 T hci_get_route
The bluetooth shared library seems to be found and containing the required functions, but the linking phase doesn't achieve.
The solution is astonished (to me): the order of the arguments given to gcc is important. "-lbluetooth" should be put after "simplescan.c":
$ gcc simplescan.c -lbluetooth -o simplescan # Success
$ gcc -lbluetooth simplescan.c -o simplescan # Failure
/tmp/ccWhZFXs.o: In function `main':
simplescan.c:(.text+0x79): undefined reference to `hci_get_route'
simplescan.c:(.text+0x8c): undefined reference to `hci_open_dev'
simplescan.c:(.text+0x132): undefined reference to `hci_inquiry'
simplescan.c:(.text+0x18f): undefined reference to `ba2str'
simplescan.c:(.text+0x1f0): undefined reference to `hci_read_remote_name'
collect2: error: ld returned 1 exit status
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With