use cmake build xbindkeys:error unknown type name 'Display'

Viewed 232

env: ubuntu20.04 cmake3.15

I download xbindkeys from:https://www.nongnu.org/xbindkeys/ and try to use cmake to build it. I can build it successful with native configure(autoconf), but when i use cmake always get the unknown type name error; the cmakelist.txt:

cmake_minimum_required(VERSION 3.10)
project(xbindkeys LANGUAGES C VERSION 1.8.7)

#for x11
find_package(X11)
if(X11_FOUND)
        message(STATUS "X11 found")
else()
        message(STATUS "X11 NOT FOUND") 
endif(X11_FOUND)
#find_package(Boost  COMPONENTS log log_setup system thread REQUIRED)
aux_source_directory(. SRCS)
message(STATUS "all src:${SRCS}")
message(STATUS "X11 libries:${X11_LIBRARIES}")
file (GLOB H_Files "./*.h")

include_directories(./ ${X11_INCLUDE_DIR} /usr/include/X11/)
message(STATUS "cmake found x11 dir:${X11_INCLUDE_DIR}")

set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lX11")
add_executable(xbindkeys.app ${SRCS})
link_directories(${X11_LIBRARIES})
target_link_libraries(xbindkeys.app ${X11_LIBRARIES} -lX11)

after generate the makefile, and run make.get the message is below:

[ 16%] Building C object CMakeFiles/xbindkeys.app.dir/get_key.c.o
[ 33%] Building C object CMakeFiles/xbindkeys.app.dir/grab_key.c.o
In file included from /home/eton/workspace/xbindkeys/grab_key.c:18:
/home/eton/workspace/xbindkeys/grab_key.h:21:23: error: unknown type name 鈥楧isplay鈥?
   21 | extern void grab_keys(Display* dpy);
      |                       ^~~~~~~
/home/eton/workspace/xbindkeys/grab_key.h:22:29: error: unknown type name 鈥楧isplay鈥?
   22 | extern void ungrab_all_keys(Display* dpy);
      |                             ^~~~~~~
/home/eton/workspace/xbindkeys/grab_key.h:24:37: error: unknown type name 鈥楧isplay鈥?
   24 | extern void get_offending_modifiers(Display* dpy);
      |                                     ^~~~~~~
/home/eton/workspace/xbindkeys/grab_key.c: In function 鈥榞rab_keys鈥?
/home/eton/workspace/xbindkeys/grab_key.c:223:16: warning: 鈥榅KeycodeToKeysym鈥?is deprecated [-Wdeprecated-declarations]
  223 |                XKeysymToString(XKeycodeToKeysym(dpy, keys[i].key.code, 0)));
      |                ^~~~~~~~~~~~~~~
In file included from /home/eton/workspace/xbindkeys/grab_key.c:20:
/usr/include/X11/Xlib.h:1687:15: note: declared here
 1687 | extern KeySym XKeycodeToKeysym(
      |               ^~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/xbindkeys.app.dir/build.make:76: CMakeFiles/xbindkeys.app.dir/grab_key.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/xbindkeys.app.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

anyone can help about this? because this question combine CMake in C-programming-language and X11 libs, not many infomation in the web. so i come here to ask.

1 Answers

eventually I reached the answer. the reason get the error like below:

grab_key.h:21:23: error: unknown type name ‘Display’

21 | extern void grab_keys(Display* dpy); | ^~~~~~~ is the header file "grab_key.h" do not contain the X11 headers.

I change content as below:

 18 #ifndef __GRABKEY_H
 19 #define __GRABKEY_H
 20 
 21 #include <X11/Xlib.h> //add this
 22 #include <X11/keysym.h> //add this
 23 extern void grab_keys(Display* dpy);
 24 extern void ungrab_all_keys(Display* dpy);
 25 
 26 extern void get_offending_modifiers(Display* dpy);
 27 
 28 extern unsigned int numlock_mask;
 29 extern unsigned int scrolllock_mask;
 30 extern unsigned int capslock_mask;
 31 
 32 #endif /* __GRABKEY_H */

then the makefile which cmake generated can success create the binary exe file.

Related