C++11程序可以使用BlueZ吗?

Can a C++11 program use BlueZ?

本文关键字:BlueZ 程序 可以使 C++11      更新时间:2023-10-16

我在使用 BlueZ 库编译一个简单的 C++11 程序时遇到问题:

#include <bluetooth/bluetooth.h>
int main() {}

在我的 Fedora 21 盒子上用g++ -std=c++11 main.cpp编译它得到:

In file included from ../scale.cpp:1:0:
/usr/include/bluetooth/bluetooth.h: In function ‘uint64_t bt_get_le64(const void*)’:
/usr/include/bluetooth/bluetooth.h:177:9: error: expected identifier before ‘*’ token
  return bt_get_unaligned((const uint64_t *) ptr);
         ^
...

这是BlueZ版本5.23和GCC 4.9.2。如果我删除-std=c++11标志,一切正常。

这正常吗?

默认情况下,GCC 使用 GNU 扩展编译为 C++03。如果指定-std=C++11则它将编译为 ISO C++11,而不启用扩展名。但是,如果您指定-std=gnu++11,那么您也将获得 GNU 扩展。

蓝牙.h中存在问题,只需将typeof替换为__typeof__即可修复,这里有一个参考:http://git.kernel.org/cgit/bluetooth/bluez.git/commit/lib/bluetooth.h?id=cf52a40302d0d20ccca22a7a1f53e46ef8abfca8