Results 1 to 4 of 4

Thread: g++4.8 Compiler Error: Expected identifier before * token in Bluez bluetooth.h

  1. #1
    Join Date
    Apr 2014
    Beans
    2

    Thumbs up g++4.8 Compiler Error: Expected identifier before * token in Bluez bluetooth.h

    Hi there,

    As my learning process from some online example, I am writing a simple testing bluetooth application with bluz v4.98 in CodeBlocks IDE which uses gcc4.8. The compiler produced the following build error messages:
    Code:
        /home/chris/Downloads/bluez-4.98/lib/bluetooth.h||In function ‘uint64_t bt_get_le64(void*)’:|
        /home/chris/Downloads/bluez-4.98/lib/bluetooth.h|113|warning: ISO C++ forbids braced-groups within expressions [-Wpedantic]|
        /home/chris/Downloads/bluez-4.98/lib/bluetooth.h|131|note: in expansion of macro ‘bt_get_unaligned’|
        /home/chris/Downloads/bluez-4.98/lib/bluetooth.h|115|error: expected identifier before ‘*’ token|
        /home/chris/Downloads/bluez-4.98/lib/bluetooth.h|131|note: in expansion of macro ‘bt_get_unaligned’|
        ||=== Build finished: 3 errors, 1 warnings ===|
    It also has build log as follows:
    Code:
      Compiling: main.cpp
        In file included from /home/chris/Development/projects/TestBT/main.cpp:6:0:
        /home/chris/Downloads/bluez-4.98/lib/bluetooth.h: In function ‘uint64_t bt_get_le64(void*)’:
        /home/chris/Downloads/bluez-4.98/lib/bluetooth.h:113:1: warning: ISO C++ forbids braced-groups within expressions [-Wpedantic]
        ({      \
        ^
        /home/chris/Downloads/bluez-4.98/lib/bluetooth.h:131:9: note: in expansion of macro ‘bt_get_unaligned’
           return bt_get_unaligned((uint64_t *) ptr);
             ^
       /home/chris/Downloads/bluez-4.98/lib/bluetooth.h:115:10: error: expected identifier before ‘*’ token
          typeof(*(ptr)) __v;  \
              ^
       /home/chris/Downloads/bluez-4.98/lib/bluetooth.h:131:9: note: in expansion of macro ‘bt_get_unaligned’
          return bt_get_unaligned((uint64_t *) ptr);
             ^
       compilation terminated due to -Wfatal-errors.
       Process terminated with status 1 (0 minutes, 0 seconds)
       3 errors, 1 warnings
    It seems that the compiler has difficulty in resolving syntax when doing macro replacement of bt_get_unaligned. I haven't found a solution after searching online for a long while. Could anyone point me out a solution. My source code is as follows.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sys/socket.h>
    #include <iostream>
    #include "bluetooth.h"
    #include "hci.h"
    #include "hci_lib.h"
    
    using namespace std;
    
    int main()
    {
        bdaddr_t btAddr;
        char addrStr[18];
    
        const unsigned int cls = 0x2e0300;
        const int timeout = 1000;
    
        int id = hci_get_route(NULL);
        if (id < 0)
        {
            return -1;
        }
    
        if (hci_devba(id, &bdAddr) < 0)
        {
            return -1;
        }
    
        if (ba2str(&btAddr, addrStr) < 0)
        {
            return -1;
        }
    
        int fh = hci_open_dev(id);
        if (fh < 0)
        {
            return -1;
        }
    
        int rv = hci_write_class_of_dev(fh, cls, timeout);
        if (rv != 0)
        {
            return -1;
        }
    
        hci_close_dev(fh);
    
        return 0;
    }
    Thank you
    Chris
    Last edited by lisati; April 27th, 2014 at 09:01 AM. Reason: Added [code] and [/code] tags to aid readability

  2. #2
    Join Date
    Apr 2012
    Beans
    5,405

    Re: g++4.8 Compiler Error: Expected identifier before * token in Bluez bluetooth.h

    Hello and welcome to the forums

    I don't really know anything about bluetooth development - is there any particular reason you are using a locally downloaded version (/home/chris/Downloads/bluez-4.98/lib/bluetooth.h) rather than the system-supplied /usr/include/bluetooth/bluetooth.h (from package libbluetooth-dev). Or are they different things?

  3. #3
    Join Date
    Apr 2014
    Beans
    2

    Re: g++4.8 Compiler Error: Expected identifier before * token in Bluez bluetooth.h

    Hi,

    The problem occurred with the header file from /usr/include/bluetooth/bluetooth.h. This is why I downloaded and tried a local copy. It has the same problem. Can anyone with the experience and the fix answer?

    Regards
    Chris

  4. #4
    Join Date
    Apr 2012
    Beans
    5,405

    Re: g++4.8 Compiler Error: Expected identifier before * token in Bluez bluetooth.h

    Well it compiles for me (both on 64-bit Saucy and 32-bit Precise) using the standard libbluetooth-dev from the repo - provided I correct what is most likely a typo in one of your variable names:

    Code:
    $ g++ -Wall -I /usr/include/bluetooth -o chris201.o -c chris201.cpp
    chris201.cpp: In function ‘int main()’:
    chris201.cpp:26:24: error: ‘bdAddr’ was not declared in this scope
         if (hci_devba(id, &bdAddr) < 0)
                            ^
    After changing the reference from &btAddr to &bdAddr
    Code:
    $ diff chris201.cpp chris201.cpp.orig 
    26c26
    <     if (hci_devba(id, &btAddr) < 0)
    ---
    >     if (hci_devba(id, &bdAddr) < 0)
    then it appears to compile OK
    Code:
    $ g++ -Wall -I /usr/include/bluetooth -o chris201.o -c chris201.cpp
    $ 
    $ file chris201.o 
    chris201.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
    For the record:
    Code:
    $ g++ --version
    g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
    Copyright (C) 2013 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    $ apt-cache policy libbluetooth-dev 
    libbluetooth-dev:
      Installed: 4.101-0ubuntu8b1
      Candidate: 4.101-0ubuntu8b1
      Version table:
     *** 4.101-0ubuntu8b1 0
            500 http://ca.archive.ubuntu.com/ubuntu/ saucy/main amd64 Packages
            100 /var/lib/dpkg/status

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •