How to fix GCC fatal error: X11/Xlib.h: No such file or directory on Ubuntu

Problem

While trying to compile a C/C++ software, you see an error message such as

wmname.c:6:10: fatal error: X11/Xlib.h: No such file or directory
    6 | #include <X11/Xlib.h>
      |          ^~~~~~~~~~~~
compilation terminated.

Solution

You need to install the libx11-dev package:

sudo apt install libx11-dev

This package contains the necessary header files for X11 development.

After installing it, try to compile your software again.