首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用bluez gatt api编译代码

使用bluez gatt api编译代码
EN

Stack Overflow用户
提问于 2015-07-28 09:42:05
回答 1查看 2.3K关注 0票数 5

我目前正在使用C中的 api实现服务器,我需要使用具有自定义特性的自己的服务。

问题是bluez5没有安装GATT api的所有标头。libbluetooth中的相同问题并不能提供所有外部GATTapi。

我用错api了吗?编译我的代码的技巧是什么?当前的脏解决方案是用我自己的代码替换bluez源代码的工具目录中的bluez,以便能够dev/test我的实现。

编辑:我使用的是最后一个稳定版本的bluez5.32

我需要编译代码的来自bluez的头:

代码语言:javascript
复制
#include "lib/bluetooth.h"
#include "lib/hci.h"
#include "lib/hci_lib.h"
#include "lib/l2cap.h"
#include "lib/uuid.h"

#include "src/shared/mainloop.h"
#include "src/shared/util.h"
#include "src/shared/att.h"
#include "src/shared/queue.h"
#include "src/shared/timeout.h"
#include "src/shared/gatt-db.h"
#include "src/shared/gatt-server.h"

职能:

代码语言:javascript
复制
[arthur ] make 2>&1 | grep gatt_ | grep implicit
tools/btgatt-server.c:32:2: error: implicit declaration of function ‘gatt_db_attribute_read_result’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:60:2: error: implicit declaration of function ‘gatt_db_add_service’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:67:2: error: implicit declaration of function ‘gatt_db_service_add_characteristic’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:94:2: error: implicit declaration of function ‘gatt_db_service_set_active’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:110:2: error: implicit declaration of function ‘bt_gatt_server_unref’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:111:2: error: implicit declaration of function ‘gatt_db_unref’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:186:2: error: implicit declaration of function ‘gatt_db_new’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:192:2: error: implicit declaration of function ‘bt_gatt_server_new’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:202:2: error: implicit declaration of function ‘bt_gatt_server_set_debug’ [-Werror=implicit-function-declaration]

这些包含不是由my系统上的bluez生成文件安装的。库文件也不包括我需要的函数。

EN

回答 1

Stack Overflow用户

发布于 2015-10-15 09:33:26

稍后我可能会使用dbus API。但是现在,我总是使用来自bluez5的低path(例如来自bluez5的路径: bluez5_utils-5.31/tools/btgatt-server.c)。为了在bluez5源目录之外编译这个独立的代码,我使用了来自bluez5的一些包含/库:

  • libshared-mainloop.a
  • libbluetooth-internal.a

就我而言,我是和buildroot一起工作的。因此,我在bluez5 mk文件中添加了一些代码,以获得缺少的库:

代码语言:javascript
复制
define BLUEZ5_UTILS_EXTERNALIZE_GATT
    mkdir -p $(STAGING_DIR)/usr/local/bluez5/gatt
    cp $(BLUEZ5_UTILS_SRCDIR)/src/uuid-helper.o $(STAGING_DIR)/usr/local/bluez5/gatt/.
    cp $(BLUEZ5_UTILS_SRCDIR)/src/.libs/libshared-mainloop.a $(STAGING_DIR)/usr/local/bluez5/gatt/.
    cp $(BLUEZ5_UTILS_SRCDIR)/lib/.libs/libbluetooth-internal.a $(STAGING_DIR)/usr/local/bluez5/gatt/.

    $(INSTALL) -D -m 0755 $(@D)/tools/btmgmt $(STAGING_DIR)/usr/bin/btmgmt
    $(INSTALL) -D -m 0755 $(@D)/tools/btmgmt $(TARGET_DIR)/usr/bin/btmgmt
endef

然后,在我的Makefile中,我只需要链接到这些库+添加-I来查找bluez5源目录中缺少的头文件:

代码语言:javascript
复制
# find bluez5 header
HEADER += -I$(BLUEZ_PATH)

# link bluez5 libraries
BLUEZ5_LIB = $(STAGING_DIR)/usr/local/bluez5/gatt/libshared-mainloop.a BLUEZ5_LIB += $(STAGING_DIR)/usr/local/bluez5/gatt/libbluetooth-internal.a

无论如何,这可能不是最好的方法,但它是伟大的工作。此外,you don't need to do anything if you upgrade your bluez5 version.我找到了一些其他的解决方案,比如叉bluez5,并在Makefile中进行了一些修改,以构建一个包含我需要的所有东西的静态库。但是这个解决方案真的很痛苦,您需要在每个新的bluez5版本上更新您的工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31672687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档