Discussion:
[libhid-discuss] Problem compiling C++ programs with libhid
Christopher
2008-08-24 04:49:37 UTC
Permalink
I'm having a problem using the headers from libhid, specifically hid.h.
If I use it in a .c file it compiles fine, but if I rename the file to
.cpp I get a bunch of errors. This is the testcase I made:
#include <hid.h>

int main()
{
HIDInterfaceMatcher broken;
return 0;
}

Naming the file "brokenhid.c" and compiling using "gcc brokenhid.c"
works fine, but "g++ brokenhid.c" gives the following errors:

"In file included from brokenhid.c:1:
/usr/include/hid.h:72: error: typedef ?_Bool? is initialized (use
__typeof__ instead)
/usr/include/hid.h:72: error: ?matcher_fn_t? was not declared in this scope
/usr/include/hid.h:79: error: ?matcher_fn_t? does not name a type
/usr/include/hid.h:124: error: ?_Bool? does not name a type
/usr/include/hid.h:133: error: ?_Bool? does not name a type"

Naming the file "brokenhid.cpp" and compiling with either gcc or g++
causes the same errors. My first thought was to wrap the #include in
'extern "C"', but that had no effect.
Anyone know what's wrong? I'm new to programming for Linux (recently
migrated from Windows)
Marian Aldenhoevel
2008-08-24 08:08:40 UTC
Permalink
Hi,
Post by Christopher
I'm having a problem using the headers from libhid, specifically hid.h.
If I use it in a .c file it compiles fine, but if I rename the file to
.cpp I get a bunch of errors.
/usr/include/hid.h:72: error: typedef ?_Bool? is initialized (use
__typeof__ instead)
/usr/include/hid.h:72: error: ?matcher_fn_t? was not declared in this scope
/usr/include/hid.h:79: error: ?matcher_fn_t? does not name a type
/usr/include/hid.h:124: error: ?_Bool? does not name a type
/usr/include/hid.h:133: error: ?_Bool? does not name a type"
I am using libhid in a C++ program and it works fine. I have come across
the same problem, though. I think you want to include <stdbool.h> if you
have it.

#include <stdbool.h>
#include <hid.h>

int main()
{
HIDInterfaceMatcher broken;
return 0;
}

I do not exactly know why, because hid.h does test for it and has #defines
to define it's own version of _Bool. So it should work without stdbool.h
as well.

In my case I use autoconf/automake and the AC_HEADER_STDBOOL macro. That
checks for the presence of stdbool.h and if found defines HAVE_STDBOOL_H
which then makes hid.h include <stdbool.h> and everything is fine.

The autotools make life a lot easier.

Ciao, MM

Loading...