系统相关
首页 > 系统相关> > C&socket.h中的Linux蓝牙编程

C&socket.h中的Linux蓝牙编程

作者:互联网

我是一个新的stackoverflow用户!我正在写作,因为我在KUbuntu 12.04上使用C编程蓝牙时遇到了一些问题.

我正试图通过我在这个pdf(启动连接)中找到的程序将设备(LEGO Mindstorm Brick)连接到我的笔记本:
NXT_Bluetooth_Handout

我安装了以下软件包:
  – bluez-hcidump,通讯调试工具
  – bluez,Linux蓝牙堆栈和相关工具
  – 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>

主要是我遇到两个问题:
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是这个库提供的另一个函数,它可以正常工作.

2)如果我修改代码以使用ba2str而不是str2ba函数我得到一个与套接字相关的错误:

$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

有人知道如何解决这些问题吗?
我希望以足够清晰的方式描述所有情况……我为我糟糕的英语道歉!

非常感谢你!!

解决方法:

对于第二个问题:您必须发布您编写的代码.否则我们无法弄清楚什么是坏事.

对于第一个问题:在调用GCC时,需要将库链接器标志作为最后一个参数:

gcc nxt_bt_connect.c -o nxt_bt_connect -lm -lbluetooth

标签:c-3,linux,bluetooth,lego,bluez
来源: https://codeday.me/bug/20190626/1290102.html