天天看點

使用blueZ進行藍牙程式設計時需要注意的問題

  一:不要用到哪個Bluez頭檔案中定義的内容就隻去包含這個頭檔案。而應該将bluetooth/bluetooth.h最先加入。類似:

#include <bluetooth/bluetooth.h> //BTPROTO_HCI

#include <bluetooth/hci.h>          //struct hci_dev_info

#include <bluetooth/hci_lib.h>     //hci_devid()

#include <bluetooth/l2cap.h>      //l2cap

#include <bluetooth/hidp.h>       //hidp

二:因為Linux 下Bluetooth實作是通過socket來完成的。sa_family_t會被使用。

bluetooth/hci.h中就用到了。是以必須在include bluetooth header file之前,include socket header file.

#include <sys/types.h> 

#include <sys/socket.h>

否則就會出現類似以下問題:

bluetooth/hci.h:1091: error: expected specifier-qualifier-list before 'sa_family_t'

繼續閱讀