c++ - 在 RaspberryPi 上使用 gcc 编译蓝牙问题

标签 c++ c gcc bluetooth raspbian

我正在使用 Raspbian (Debian Wheezy)。我已经安装了

$ sudo apt-get install bluez bluez-tools bluez-dbg bluez-hcidump bluez-tools python-bluez libbluetooth-dev libbluetooth3 libbluetooth3-dbg

但是当尝试编译以下行时,它说它不知道该库:

$ gcc scanbd.c -o scanbd
/tmp/ccl5BrFc.o: In function `main':
scanbd.c:(.text+0x84): undefined reference to `hci_get_route'
scanbd.c:(.text+0x90): undefined reference to `hci_open_dev'
scanbd.c:(.text+0x11c): undefined reference to `hci_inquiry'
scanbd.c:(.text+0x170): undefined reference to `ba2str'
scanbd.c:(.text+0x1c8): undefined reference to `hci_read_remote_name'
collect2: ld returned 1 exit status

这些是我的 .c 文件中的包含语句:

#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>

有人知道我做错了什么吗? 谢谢

更新:事实证明我做了所有正确的事情,但我必须关闭/拔掉 RPi,然后重新启动才能使一切正常工作...-lbluetooth 位于之后的路径中。 谢谢大家

最佳答案

希望以下链接可以帮助您。

Linking with libbluetooth.so

编译时,请将参数-lbluetooth放在scannbd.c后面,如下:

例如: gcc scanbd.c -lbluetooth -o scanbd

关于c++ - 在 RaspberryPi 上使用 gcc 编译蓝牙问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24478767/

相关文章:

c++ - __m128i 变量是否为零?

python - 如何使用 SWIG 包装 HWND 和 HINSTANCE 类型?

c - g_strdupv 函数的段错误

c++ - 如何在 C 中使用 google mock?

C++ 随机数

c++ - 如何在 Qt 样式表中使用嵌入字体?

c++ - 为什么 auto_ptr 构造不能使用 = 语法

c++ - 如何从 gcc 的预编译头文件中获益最多?

c++ - 构建没有 CRT 和默认 header 的控制台应用程序?

c++ - 检测类是否具有带签名的构造函数