1

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.

Ignat Insarov
  • 4,660
  • 18
  • 37

1 Answers1

0

research into the XKBrules.h file contents indicates that it is for C++ programs, not C programs

this web page gives some further info:

http://xmonad.org/xmonad-docs/X11/Graphics-X11-Xlib-Types.html

Which amongst other things says:

Graphics.X11.Xlib.Types

A collection of type declarations for interfacing with Xlib.

Synopsis
Documentation

newtype Display
Source

pointer to an X11 Display structure

Constructors
Display (Ptr Display)    

Instances
Eq Display   
Data Display     
Ord Display  
Show Display     
Typeable Display     

Strongly suggest asking this question on a C++ forum

user3629249
  • 16,402
  • 1
  • 16
  • 17
  • 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. Appears it should be quite widespread. – Ignat Insarov Jan 21 '17 at 21:39