How to link C code to which Bluetooth library ? ( Linux)
-
I am trying to port this C code into C++. I am stuck linking to library - few reasons which library am I supposed to use - libbluetooth or bluetooth ? I am using QTCreator ( pseudo IDE) and really do not know how the access the compiler / linker directly , hence not sure if I need to add "-l" but I can figure that out when I manage to actually find either library file - so far no luck ( and did ask elsewhere for help with that ) This very old basic C code and there is no way to ask the author. I just need some assistance to link this code to correct library. Thanks, any help with the library issue will be greatly appreciated .
To compile our program, invoke gcc and link against libbluetooth
gcc -o simplescan simplescan.c -lbluetooth
Example 4-1. simplescan.c
#include
#include
#include
#include
#include
#include
#includeint main(int argc, char **argv)
{
inquiry_info *ii = NULL;
int max_rsp, num_rsp;
int dev_id, sock, len, flags;
int i;
char addr[19] = { 0 };
char name[248] = { 0 };dev\_id = hci\_get\_route(NULL); sock = hci\_open\_dev( dev\_id ); if (dev\_id < 0 || sock < 0) { perror("opening socket"); exit(1); } len = 8; max\_rsp = 255; flags = IREQ\_CACHE\_FLUSH; ii = (inquiry\_info\*)malloc(max\_rsp \* sizeof(inquiry\_info)); num\_rsp = hci\_inquiry(dev\_id, len, max\_rsp, NULL, &ii, flags); if( num\_rsp < 0 ) perror("hci\_inquiry"); for (i = 0; i < num\_rsp; i++) { ba2str(&(ii+i)->bdaddr, addr); memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(sock, &(ii+i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("%s %s\\n", addr, name); } free( ii ); close( sock ); return 0;
}
-
I am trying to port this C code into C++. I am stuck linking to library - few reasons which library am I supposed to use - libbluetooth or bluetooth ? I am using QTCreator ( pseudo IDE) and really do not know how the access the compiler / linker directly , hence not sure if I need to add "-l" but I can figure that out when I manage to actually find either library file - so far no luck ( and did ask elsewhere for help with that ) This very old basic C code and there is no way to ask the author. I just need some assistance to link this code to correct library. Thanks, any help with the library issue will be greatly appreciated .
To compile our program, invoke gcc and link against libbluetooth
gcc -o simplescan simplescan.c -lbluetooth
Example 4-1. simplescan.c
#include
#include
#include
#include
#include
#include
#includeint main(int argc, char **argv)
{
inquiry_info *ii = NULL;
int max_rsp, num_rsp;
int dev_id, sock, len, flags;
int i;
char addr[19] = { 0 };
char name[248] = { 0 };dev\_id = hci\_get\_route(NULL); sock = hci\_open\_dev( dev\_id ); if (dev\_id < 0 || sock < 0) { perror("opening socket"); exit(1); } len = 8; max\_rsp = 255; flags = IREQ\_CACHE\_FLUSH; ii = (inquiry\_info\*)malloc(max\_rsp \* sizeof(inquiry\_info)); num\_rsp = hci\_inquiry(dev\_id, len, max\_rsp, NULL, &ii, flags); if( num\_rsp < 0 ) perror("hci\_inquiry"); for (i = 0; i < num\_rsp; i++) { ba2str(&(ii+i)->bdaddr, addr); memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(sock, &(ii+i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("%s %s\\n", addr, name); } free( ii ); close( sock ); return 0;
}
-
I am trying to port this C code into C++. I am stuck linking to library - few reasons which library am I supposed to use - libbluetooth or bluetooth ? I am using QTCreator ( pseudo IDE) and really do not know how the access the compiler / linker directly , hence not sure if I need to add "-l" but I can figure that out when I manage to actually find either library file - so far no luck ( and did ask elsewhere for help with that ) This very old basic C code and there is no way to ask the author. I just need some assistance to link this code to correct library. Thanks, any help with the library issue will be greatly appreciated .
To compile our program, invoke gcc and link against libbluetooth
gcc -o simplescan simplescan.c -lbluetooth
Example 4-1. simplescan.c
#include
#include
#include
#include
#include
#include
#includeint main(int argc, char **argv)
{
inquiry_info *ii = NULL;
int max_rsp, num_rsp;
int dev_id, sock, len, flags;
int i;
char addr[19] = { 0 };
char name[248] = { 0 };dev\_id = hci\_get\_route(NULL); sock = hci\_open\_dev( dev\_id ); if (dev\_id < 0 || sock < 0) { perror("opening socket"); exit(1); } len = 8; max\_rsp = 255; flags = IREQ\_CACHE\_FLUSH; ii = (inquiry\_info\*)malloc(max\_rsp \* sizeof(inquiry\_info)); num\_rsp = hci\_inquiry(dev\_id, len, max\_rsp, NULL, &ii, flags); if( num\_rsp < 0 ) perror("hci\_inquiry"); for (i = 0; i < num\_rsp; i++) { ba2str(&(ii+i)->bdaddr, addr); memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(sock, &(ii+i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("%s %s\\n", addr, name); } free( ii ); close( sock ); return 0;
}