Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to link C code to which Bluetooth library ? ( Linux)

How to link C code to which Bluetooth library ? ( Linux)

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialc++visual-studio
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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
    #include

    int 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;
    

    }

    K L 2 Replies Last reply
    0
    • L Lost User

      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
      #include

      int 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;
      

      }

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      asked and answered in QA, I think.

      Keep Calm and Carry On

      1 Reply Last reply
      0
      • L Lost User

        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
        #include

        int 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;
        

        }

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        And previously answered back in March this year: Re: How to find what name and where the (bluetooth) library is located? - Linux Programming Discussion Boards[^].

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups