X11/Xlib.h' file not found

I'm trying to compile a little program (xkblayout-state) which display the keyboard layout but for some reason it failed to compile because Xlib.h is missing but the library is on my sistem. Why I need this program? Because I have four layouts and sometimes it's difficult to navigate without knowing which layout is active.
Also my knowledge of C++ are at basic level so any suggestion on how to compile this program is more then welcome! Thank you!
Code:
 $gmake                                                                                                                                                        
c++ -O2 -Wall -c -o XKeyboard.o XKeyboard.cpp
In file included from XKeyboard.cpp:14:
./XKeyboard.h:20:10: fatal error: 'X11/Xlib.h' file not found
#include <X11/Xlib.h>
         ^~~~~~~~~~~~
1 error generated.
gmake: *** [Makefile:13: XKeyboard.o] Error 1

Code:
 $locate Xlib.h                                                                                                                                          
/usr/local/include/X11/Xlib.h
 
O.K., that tip helped but it still fails to build. Invoking gmake -v tells me the gmake version.

Code:
gmake                                                                                                                                                          
c++ -O2 -Wall -c -o XKeyboard.o XKeyboard.cpp -I/usr/local/include
c++ -O2 -Wall -c -o wrapper.o wrapper.cpp -I/usr/local/include
c++ -O2  -o xkblayout-state XKeyboard.o wrapper.o -I/usr/local/include
XKeyboard.o: In function `XKeyboard::XKeyboard()':
XKeyboard.cpp:(.text+0x55): undefined reference to `XkbIgnoreExtension'
XKeyboard.cpp:(.text+0x8f): undefined reference to `XkbOpenDisplay'
XKeyboard.cpp:(.text+0xcc): undefined reference to `XkbSelectEventDetails'
XKeyboard.cpp:(.text+0xde): undefined reference to `XkbGetState'
XKeyboard.cpp:(.text+0xfc): undefined reference to `XkbGetState'
XKeyboard.o: In function `XKeyboard::initializeXkb()':
XKeyboard.cpp:(.text+0x5cc): undefined reference to `XkbQueryExtension'
XKeyboard.cpp:(.text+0x5d1): undefined reference to `XkbAllocKeyboard'
XKeyboard.cpp:(.text+0x5fb): undefined reference to `XkbGetControls'
XKeyboard.cpp:(.text+0x60b): undefined reference to `XkbGetNames'
XKeyboard.cpp:(.text+0x61b): undefined reference to `XkbGetNames'
XKeyboard.cpp:(.text+0x7cc): undefined reference to `XGetAtomName'
XKeyboard.cpp:(.text+0x8d4): undefined reference to `XFree'
XKeyboard.cpp:(.text+0x923): undefined reference to `XGetAtomName'
XKeyboard.cpp:(.text+0x93a): undefined reference to `XFree'
XKeyboard.cpp:(.text+0xc6a): undefined reference to `XkbGetState'
XKeyboard.o: In function `XKeyboard::accomodateGroupXkb()':
XKeyboard.cpp:(.text+0xe97): undefined reference to `XkbGetState'
XKeyboard.o: In function `XKeyboard::~XKeyboard()':
XKeyboard.cpp:(.text+0x18c1): undefined reference to `XCloseDisplay'
XKeyboard.o: In function `XKeyboard::currentGroupNum() const':
XKeyboard.cpp:(.text+0x1b26): undefined reference to `XkbGetState'
XKeyboard.o: In function `XKeyboard::currentGroupName() const':
XKeyboard.cpp:(.text+0x1b5c): undefined reference to `XkbGetState'
XKeyboard.o: In function `XKeyboard::currentGroupSymbol() const':
XKeyboard.cpp:(.text+0x1bac): undefined reference to `XkbGetState'
XKeyboard.o: In function `XKeyboard::currentGroupVariant() const':
XKeyboard.cpp:(.text+0x1bfc): undefined reference to `XkbGetState'
XKeyboard.o: In function `XKeyboard::setGroupByNum(int)':
XKeyboard.cpp:(.text+0x1c4d): undefined reference to `XkbLockGroup'
XKeyboard.cpp:(.text+0x1c60): undefined reference to `XkbGetState'
XKeyboard.o: In function `XKeyboard::changeGroup(int)':
XKeyboard.cpp:(.text+0x1c9e): undefined reference to `XkbLockGroup'
XKeyboard.cpp:(.text+0x1cb1): undefined reference to `XkbGetState'
c++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake: *** [Makefile:16: xkblayout-state] Error 1


Anyway I've solved my problem with the help of x11/xkb-switch and sh scripting. I'm guessing the next step it's to mark the thread: solved or since the initial problem is not solved, xkblayout-state build fails the thread should remain open?
 
If you have to use the -I switch in your make file to find the header files while compiling, you probably also have to use the -L switch to find link libraries while linking. Most likely simply adding "-L /usr/local/lib" will already be sufficient. But you really need to understand how make files work, how the -I and -L switches work, and that the layout (install location) of header files and link libraries can be different on different OSes. You should probably start by looking where the X11 installation lives on your computer.

I think since the second problem is a direct followup to the first one, using the same thread is a space-saving measure.
 
Back
Top