I'm writing a Haskell program that is supposed to know some details about X11 state, so I try to define an FFI that would call relevant X11 shared libraries' symbols. I generally follow the instructions from the wikibook. When I add an include
directive that refers to an official X11 header, hsc2hs
throws a bucket of errors at me, as if said header is syntactically incorrect. I had to resort to writing my own header that essentially replicates the bits I need from the upstream header file and that let my code compile.
Specifically, I need _XkbRF_VarDefs
that is declared in X11/extensions/XKBrules.h
. You can review my code at the repository: commit 4d77785 contains the header I had to write to have it compile, while in 8d5e76c you will find my latest attemts to include the official header that fail to compile (you may see the error log below).
Is it the official header that is broken? Or is it hsc2hs
? Are there some magic flags I need to add to the hsc2hs
invocation in my make script to have it compile with the official header?
The error log:
In file included from ShowKeyboardLayout.hsc:17:0:
/usr/include/X11/extensions/XKBrules.h:106:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’
extern Bool XkbRF_GetComponents(
^~~~~~
/usr/include/X11/extensions/XKBrules.h:106:8: error: unknown type name ‘Bool’
extern Bool XkbRF_GetComponents(
^~~~
/usr/include/X11/extensions/XKBrules.h:118:8: error: unknown type name ‘Bool’
extern Bool XkbRF_LoadRules(
^~~~
/usr/include/X11/extensions/XKBrules.h:119:5: error: unknown type name ‘FILE’
FILE * /* file */,
^~~~
/usr/include/X11/extensions/XKBrules.h:123:8: error: unknown type name ‘Bool’
extern Bool XkbRF_LoadRulesByName(
^~~~
/usr/include/X11/extensions/XKBrules.h:145:8: error: unknown type name ‘Bool’
extern Bool XkbRF_LoadDescriptions(
^~~~
/usr/include/X11/extensions/XKBrules.h:146:5: error: unknown type name ‘FILE’
FILE * /* file */,
^~~~
/usr/include/X11/extensions/XKBrules.h:150:8: error: unknown type name ‘Bool’
extern Bool XkbRF_LoadDescriptionsByName(
^~~~
/usr/include/X11/extensions/XKBrules.h:159:5: error: unknown type name ‘Bool’
Bool /* wantDesc */,
^~~~
/usr/include/X11/extensions/XKBrules.h:160:5: error: unknown type name ‘Bool’
Bool /* wantRules */
^~~~
/usr/include/X11/extensions/XKBrules.h:172:5: error: unknown type name ‘Bool’
Bool /* freeRules */
^~~~
/usr/include/X11/extensions/XKBrules.h:182:8: error: unknown type name ‘Bool’
extern Bool XkbRF_GetNamesProp(
^~~~
/usr/include/X11/extensions/XKBrules.h:183:4: error: unknown type name ‘Display’
Display * /* dpy */,
^~~~~~~
/usr/include/X11/extensions/XKBrules.h:188:8: error: unknown type name ‘Bool’
extern Bool XkbRF_SetNamesProp(
^~~~
/usr/include/X11/extensions/XKBrules.h:189:4: error: unknown type name ‘Display’
Display * /* dpy */,
^~~~~~~
ShowKeyboardLayout.hsc:19:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
type Display = Int -- cz idk
^~~
compiling ./ShowKeyboardLayout_hsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c ./ShowKeyboardLayout_hsc_make.c -o ./ShowKeyboardLayout_hsc_make.o -fno-stack-protector -I/usr/lib/ghc-8.0.1/include/
P.S. In the comments, it's remarked that XKBrules.h
is not present in an installation of Ubuntu. I use Arch Linux and the file is found in extra/libxkbfile package, which is a dependency of gnome-desktop, xorg-setxkbmap and xterm, among others.