LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Gtk-warning **: Cannot Open Display: (http://www.linuxquestions.org/questions/programming-9/gtk-warning-%2A%2A-cannot-open-display-289318/)

davikevi 02-12-2005 11:33 AM

Gtk-warning **: Cannot Open Display:
 
have successfully compiled a helloworld program (helloworld.c) by using:
gcc -o helloworld helloworld.c `gtk-config --libs --cflags`

But I don't know why I got the error: "cannot open display: :0.0" when i enter ./helloworld

I try to enter "xhost +" but I get this error message:
"xhost: unable to open display ":0.0"

I am using the Fedora Core release 1 linux and login as root a/c with
gtk:1.2.10 glib:1.2.10.

how I can solve this problem?

P.S:
This is my helloworld.c file:

#include <gtk/gtk.h>

gint main(gint argc, gchar *argv[])
{
GtkWidget *window, *widget;

gtk_set_locale();
gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "hiGTK+");
gtk_window_set_default_size(GTK_WINDOW(window), 140, 40);

gtk_signal_connect(GTK_OBJECT(window), "destroy",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

widget = gtk_button_new_with_label("hello!");
// widget = gtk_label_new("hello");
gtk_container_add(GTK_CONTAINER(window), widget);

gtk_widget_show_all(window);
gtk_main();

g_print("bye\n");

return (0);
}

acid_kewpie 02-12-2005 12:06 PM

you're running it as root aren't you? don't... run it as the user who is logged into the x server. alternaitevly, run "xhost +localhost" to allow any local user to load X displays.

kpachopoulos 02-18-2005 01:40 PM

What does this message mean? I think it can appear in many different occasions. I just installed xchat as root; it works perfect (as root), although i don't use it. When i "su" as a different user this message appears. Does this have to do with the fact, that i am logged in as root and i am trying to run the program as a user? How can i fix this problem? Thanks

skoona 02-19-2005 12:42 AM

is that the only error message ? error: "cannot open display: :0.0"

gtk rarely gives only one. Anyway, the program looks fine -- unless some of those statements are gtk-+2.0.

note: doing everything as root is BAD practice, that's all. Most things work as root.

Is it possible for you to upgrade to FC3? and trythis again. This is the command I had to use to compile your program.

Code:

$ gcc -o helloworld helloworld.c `pkg-config gtk+-2.0 --libs --cflags`
Notice the change from 'gtk-config...' to 'pkg-config gtk+-2.0...'

(please answer - is that the only error message)


All times are GMT -5. The time now is 07:21 AM.