While running a GTK+ based C program under Cygwin, the following runtime error is observed,
Gtk-WARNING **: cannot open display:
Make sure that Cygwin/XServer is installed and is running. If it is not installed, download the relevant
packages from Cygwin.
Make sure that environment variable DISPLAY is defined in the shell's environment. If DISPLAY is not defined,
it can be defined by giving the following commands from shell,
DISPLAY=":0"You can, alternatively, put the following code in the .bashrc file,
if [[ -z "$DISPLAY" ]]
Better still, put the code for setting the environment variable, DISPLAY, in the source code. This can be done
by putting the following lines at the beginning of the main function of the
// introduce the environment variable
// DISPLAY, if not present
if (setenv ("DISPLAY", ":0", 0) == -1)
This will obviate the requirement of setting the environment variable and is particularly helpful if you wish to run the program directly under Windows.