私は新しいstackoverflowユーザーです!KUbuntu 12.04でCを使用してBluetoothをプログラミングする際に問題が発生したため、この記事を書いています。
このPDF(接続の開始)で見つけたプログラムを介してデバイス(レゴマインドストームブリック)をノートブックに接続しようとしています: NXT_Bluetooth_Handout
次のパッケージをインストールしました:-bluez-hcidump、通信デバッグツール-bluez、Linux Bluetoothスタックおよび関連ツール-libBluetooth3、BlueZライブラリ-libBluetooth-dev、BlueZライブラリにリンクするための開発ファイル
// Socket, used for Bluetooth socket
#include <sys/socket.h>
#include <sys/types.h>
// Bluetooth headers
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
主に2つの問題が発生しました。1)プログラムをコンパイルしようとすると、次のようになります。
$ gcc -lm -lbluetooth nxt_bt_connect.c -o nxt_bt_connect
/tmp/ccSLdkpn.o: In function `init_bluetooth':
nxt_bt_connect.c:(.text+0x60): undefined reference to `str2ba'
collect2: ld returned 1 exit status
ここで、str2baはBlueZ関数であり、機能するはずです... ba2strは、このライブラリが提供するもう1つの関数であり、問題なく機能します。
2)str2ba関数の代わりにba2strを使用するためにコードを変更すると、ソケットに関連するエラーが発生します。
$ gcc -lm -lbluetooth 1.c -o nxt_bt_connect2
1.c: In function ‘main’:
1.c:101:23: error: called object ‘socket’ is not a function
問題は、ソケットヘッダーがsys /になっていないことです。実際、次のコマンドを実行すると、次のようになります。
find /usr/include/ -name socket.h
/usr/include/gtkmm-2.4/gtkmm/socket.h
/usr/include/linux/socket.h
/usr/include/asm-generic/socket.h
/usr/include/giomm-2.4/giomm/socket.h
/usr/include/x86_64-linux-gnu/sys/socket.h
/usr/include/x86_64-linux-gnu/asm/socket.h
/usr/include/x86_64-linux-gnu/bits/socket.h
それらの問題を解決する方法を知っている人はいますか?すべての状況を十分に明確に説明したいと思います...英語が下手であることをお詫びします!
どうもありがとうございます!!