Search code examples
windowsopencvcygwinxserver

Run a gui application on cygwin


I am building application that is using OpenCV lib to show images. The application fails at the following line:

cv::namedWindow(....);

I am using cygwin on Windows 10, and using CLion IDE.

The executable is built successfully but when run it shows the following error:

(Display Image:10340): Gtk-WARNING **: cannot open display:

I made sure xinit is installed and its dependencies using cygwin setup. I've run the x server using a batch file with the following content:

c:\cygwin\bin\run.exe -p /usr/X11R6/bin XWin -listen tcp -multiwindow -clipboard -silent-dup-error

And I can see the 'X' icon in notification icons area, but still getting the error when I try to run the executable. I tried running it both from CLion and from cygwin console but same result.

What is it that I am missing?


Solution

  • To run a program that need access to a X Server you need:

    1) a running X Server
    2) the variable DISPLAY defined

    If you check from Xterm you will have:

    $ echo $DISPLAY
    :0.0
    

    So your program can run as DISPLAY is defined and the X server is found.