我正在编写一个Haskell程序,该程序应该知道有关X11状态的一些细节,所以我尝试定义一个可以调用相关X11共享库符号的FFI。我通常按照wikibook的说明操作。当我添加引用官方X11标头的include
指令时,hsc2hs
会向我抛出一堆错误,就好像所述标头在语法上不正确一样。我不得不求助于编写自己的头文件,它基本上复制了我需要的上游头文件中的位,并让我的代码编译。
具体来说,我需要_XkbRF_VarDefs
中声明的X11/extensions/XKBrules.h
。您可以在repository查看我的代码:commit 4d77785 包含我必须编写的标题以便编译,而在 8d5e76c 中,您将找到我最新的attemts包括无法编译的官方标题(您可能会在下面看到错误日志)。
官方标题是否被破坏?或者是hsc2hs
?我需要在make脚本中为hsc2hs
调用添加一些魔术标记,以便使用官方标题进行编译吗?
错误日志:
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。在评论中,有人指出在Ubuntu的安装中不存在XKBrules.h
。我使用Arch Linux,该文件位于 extra / libxkbfile 包中,该包依赖于 gnome-desktop , xorg-setxkbmap 和< em> xterm 等等。
答案 0 :(得分:0)
对XKBrules.h文件内容的研究表明它适用于C ++程序,而不是C程序
此网页提供了更多信息:
其中包括:
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
强烈建议在C ++论坛上提出这个问题