Search code examples
c++gtkx11gtkmm

Gtkmm can't open application window on OSX


I've installed gtkmm3 via homebrew. My project links and builds without errors but never opens a window. xQuartz/X11 fires up upon successful build as well. It just seems to hang during the Gtk::Application::create() call. I've included my code below. Building on Xcode 5.1. Any help is much appreciated.

Thanks

#include <iostream>
#include <gtkmm-3.0/gtkmm.h>


int main(int argc, char * argv[])
{


    std::cout << "Creating Application" << std::endl;
    Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "some.thing.here");


    std::cout << "Creating Window" << std::endl;
    Gtk::Window window;

    std::cout << "Setting window title" << std::endl;
    window.set_title("Window One");


    std::cout << "Running App" << std::endl;
    return app->run(window);

}

Solution

  • Gtk::Application::create() seems to hang because X11 isn't responding to it's request for a window. In it's current (default I assume) state only root can request a window.

    Ideal solution (what worked best for me): Go to Product > Scheme > Edit Scheme in the main menu of XCode. Make sure your current scheme (or whatever your dev scheme is) is selected in the fly out menu. On the modal that opens there are a few radio buttons. Select the 'run as root' option. Now X11 should respond to the request for the window.

    Another solution: Compile program and run with sudo.

    An even more complex solution but if you intend to eventually let someone use this program via ssh...

    Use xhost to add a user and enable ssh forwarding so you can run the compiled version via ssh without sudo. There are many docs explaining how to do this so I won't put the particulars here.

    One other Note XCode generates a main function with const char argv. Gtk::Application::create() won't take a const char argv. Remove const from main's argv and everything works.