I have the following c program which launches a Gtk Program on ubuntu:
#include <unistd.h>
int main( int argc, const char* argv[] )
{
char *args[2] = { "testarg", 0 };
char *envp[1] = { 0 };
execve("/home/michael/MyGtkApp",args,envp);
}
I get “Gtk-WARNING **: cannot open display: ” and my program is not launched.
I have tried setting char *envp[1] = {"DISPLAY:0.0"}; and execute ‘xhost +‘ , I don’t see the ‘cannot open display’ warning, but my program is still not launched.
Does anyone know how to fix my problem?
Thank you.
Very wrong. Separate name and value by
=, and terminate the list byNULLlikeargs.or better yet, don’t hard-code the display, and use Xauthority too.
I’m left wondering why you give the program such a sparse environment, though – depending on how you’re configured and what you’re using, Gtk+ may not be entirely happy with
DBUS_SESSION_BUS_ADDRESS,GTK2_RC_FILES,GTK_IM_MODULE,HOME,LANG*,LC_*,PATH,XDG_*etc. environment variables gone. Why don’t you just useexecvorexecvp, and just allow the parent’s environment to be inherited?