Search code examples
c++gtkmm

GTKmm Simple example compiling error


I am trying to compile simple example from Gtkmm book. The code that I am using is in simple.cc file

#include <gtkmm.h>
int main(int argc, char *argv[])
{
auto app =
Gtk::Application::create(argc, argv,
  "org.gtkmm.examples.base");

Gtk::Window window;
window.set_default_size(200, 200);

return app->run(window);
}

and I try to compile it from command line in following way

g++ -o simple.o simple.cc `pkg-config gtkmm-3.0 --cflags --libs`

from which I get following errors:

simple.cc: In function ‘int main(int, char**)’:
simple.cc:5:8: error: ‘app’ does not name a type
auto app =
     ^
simple.cc:12:10: error: ‘app’ was not declared in this scope
return app->run(window);
       ^

I am using Linux Mint 17.3 and have gtkmm 3.10.1 installed.


Solution

  • You need to enable C++11 (or higher) in order to use auto and type deduction.

    Add

    -std=c++11
    

    to your compilation command line.