与libbluetooth.so链接 [英] Linking with libbluetooth.so

查看:469
本文介绍了与libbluetooth.so链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ubuntu 14.04上,我试图做一个蓝牙设备清单的小例子,但是在编译此简约演示时,我面临一个有关与蓝牙共享库链接的简单问题.

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.

推荐答案

(对我而言)解决方案感到惊讶:给gcc的参数顺序很重要. "-lbluetooth"应放在"simplescan.c"之后:

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

这篇关于与libbluetooth.so链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆