“Gtk-WARNING **: cannot open display:” when runnin

2020-03-30 01:21发布

问题:

I'm trying to run a gtkmm project in Eclipse CDT (On Ubuntu). The project compiles fine, there are no errors reported but when I try to run the project the console prints out this message

"Gtk-WARNING **: cannot open display:"

If I go to where the executable is located, in nautilus, I can open it and it runs fine. It's just a problem when trying to run directly from Eclipse.

Thanks,

回答1:

It sounds like the the "DISPLAY" environment variable is not being set in the environment used by eclipse to launch your application.

To check this, Edit the Run Configuration for the the program you are trying to launch. Next, select the Environment tab. If there is a DISPLAY variable already set, make sure it is correct (usually it should be ":0.0"). If there is not one, create one and set it to ":0.0".