I'm a new * user! I'm writing because I have some problems programming Bluetooth with C on my KUbuntu 12.04.
我是一个新的*用户!我写这篇文章是因为我在KUbuntu 12.04上用C编程的时候遇到了一些问题。
I'm trying to connect a device (LEGO Mindstorm Brick) to my notebook through a program that I've found in this pdf (Initiate connection): NXT_Bluetooth_Handout
我正在试图通过一个程序连接一个设备(LEGO Mindstorm Brick),通过一个我在这个pdf文件中找到的程序(启动连接):nxt_bluetooth_讲义。
I installed the following packages: - bluez-hcidump, communication debugging tool - bluez, Linux Bluetooth stack and associated tools - libBluetooth3, the BlueZ library - libBluetooth-dev, the development files for linking to the BlueZ library
我安装了以下软件包:- bluez-hcidump,通信调试工具- bluez, Linux蓝牙栈和相关工具- libbluetoo3, 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>
Mainly I encountered two problems: 1) If I simply try to compile the program I get:
主要是我遇到了两个问题: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
Where str2ba is a BlueZ function, which should work...ba2str is the other function which this library provides and it works without problem.
str2ba是一个BlueZ函数,它应该工作…ba2str是这个库提供的另一个函数,它可以毫无问题地工作。
2) If I modify the code in order to use ba2str instead of str2ba function I get an error related to the socket:
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
The problem is that I have no socket header is sys/, in fact if I run:
问题是,我没有套接字头是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
Is there someone who knows how to solve those problems? I hope to have described all situation in a sufficiently clear way...I apologize for my bad English!
有没有人知道如何解决这些问题?我希望能以足够清晰的方式描述所有的情况……我为我的糟糕英语道歉!
Thank you very much!!
非常感谢! !
2 个解决方案
#1
4
For the second question: you have to post the code you've written. Else we can't figure out what's bad.
对于第二个问题:您必须发布您所编写的代码。否则我们不知道什么是坏的。
For the first question: you need to put the library linker flags as the last parameters when invoking GCC:
对于第一个问题:您需要将库链接器标志作为调用GCC的最后一个参数:
gcc nxt_bt_connect.c -o nxt_bt_connect -lm -lbluetooth
#2
0
Assuming KUbuntu uses Debian packaging, <sys/socket.h>
aka /usr/include/sys/socket.h
comes with the libc6-dev
package.
假设KUbuntu使用Debian的包装,
#1
4
For the second question: you have to post the code you've written. Else we can't figure out what's bad.
对于第二个问题:您必须发布您所编写的代码。否则我们不知道什么是坏的。
For the first question: you need to put the library linker flags as the last parameters when invoking GCC:
对于第一个问题:您需要将库链接器标志作为调用GCC的最后一个参数:
gcc nxt_bt_connect.c -o nxt_bt_connect -lm -lbluetooth
#2
0
Assuming KUbuntu uses Debian packaging, <sys/socket.h>
aka /usr/include/sys/socket.h
comes with the libc6-dev
package.
假设KUbuntu使用Debian的包装,