I am not able to get the X11/Xlib.h header file included properly with CMake on CLion. Below is the CMakeLists.txt file:
cmake_minimum_required(VERSION 3.15)project(X11 C)set(CMAKE_C_STANDARD 11)add_compile_options(-Wall -lX11)add_executable(X11 main.c)
And the main.c file:
#include <stdio.h>#include <stdlib.h>#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/Xos.h>int main(int argc, char **argv) { Display *dpy = XOpenDisplay(NULL); return EXIT_SUCCESS;}
The error is undefined reference to 'XOpenDisplay'
. The -Wall
flag works fine and I get the unused variable warning for this snippet. Lastly, I am able to compile main.c from the command line without any problem:
gcc main.c -lX11