Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C&;插座.h_C_Linux_Bluetooth_Bluez_Lego - Fatal编程技术网

C&;插座.h

C&;插座.h,c,linux,bluetooth,bluez,lego,C,Linux,Bluetooth,Bluez,Lego,我是一个新的stackoverflow用户!我写这篇文章是因为我在KUbuntu 12.04上用C编程蓝牙时遇到了一些问题 我正在尝试通过我在本pdf(启动连接)中找到的程序将设备(乐高Mindstorm Brick)连接到我的笔记本: 我安装了以下软件包: -bluez hcidump,通信调试工具 -bluez、Linux蓝牙堆栈和相关工具 -libBluetooth3,BlueZ库 -libBluetooth dev,用于链接到BlueZ库的开发文件 // Socket, used fo

我是一个新的stackoverflow用户!我写这篇文章是因为我在KUbuntu 12.04上用C编程蓝牙时遇到了一些问题

我正在尝试通过我在本pdf(启动连接)中找到的程序将设备(乐高Mindstorm Brick)连接到我的笔记本:

我安装了以下软件包: -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>
其中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

假设KUbuntu使用Debian打包,
aka
/usr/include/sys/socket.h
附带了
libc6 dev
包。

好的,我很无知,非常感谢!!另一个文件有一些编程错误,我只是简单地修复了:-)嗨,很抱歉再次打扰你,另一个问题:如果我想为同一个程序创建一个cmake文件,我怎么能包含-lm和-lbluetooth?好吧,在文件中键入它?
gcc nxt_bt_connect.c -o nxt_bt_connect -lm -lbluetooth