Search code examples
c++mingwgtk3gtkmm3

gtkmm not found in MinGW despite being installed


I am trying to compile following simple file (demo code from one of the tutorial sites) but gtkmm.h is not being found despite being installed.

$ cat rngtk1.cpp
#include <iostream>
#include <gtkmm.h>
int
main( int argc, char* argv[] ){
 try {
  Gtk::Main m( argc, argv ) ;
  Gtk::Window win ;
  m.run( win ) ;
 }
 catch( std::exception const & exc ) {
  std::cout << exc.what() << std::endl ;
  exit( -1 ) ;
 }
 exit( 0 ) ;
}

On giving compile command:

$ g++ rngtk1.cpp
rngtk1.cpp:2:10: fatal error: gtkmm.h: No such file or directory
    2 | #include <gtkmm.h>
      |          ^~~~~~~~~
compilation terminated.

Changing to "gtkmm.h" does not help

Following show relevant packages are installed:

$ pacman -Ss gtkmm
mingw32/mingw-w64-i686-gtkmm 2.24.5-2
    C++ bindings for gtk2 (mingw-w64)
mingw32/mingw-w64-i686-gtkmm3 3.24.1-1
    C++ bindings for gtk3 (mingw-w64)
mingw64/mingw-w64-x86_64-gtkmm 2.24.5-2
    C++ bindings for gtk2 (mingw-w64)
mingw64/mingw-w64-x86_64-gtkmm3 3.24.1-1 [installed] <<<<<<<<<<<<<<<<< NOTE
    C++ bindings for gtk3 (mingw-w64)

$ pacman -Ss gtk3
mingw32/mingw-w64-i686-gtk3 3.24.10-3
    GObject-based multi-platform GUI toolkit (v3) (mingw-w64)
mingw32/mingw-w64-i686-gtkmm3 3.24.1-1
    C++ bindings for gtk3 (mingw-w64)
mingw32/mingw-w64-i686-spice-gtk 0.37-1
    GTK3 widget for SPICE clients (mingw-w64)
mingw64/mingw-w64-x86_64-gtk3 3.24.10-3 [installed] <<<<<<<<<<<<<<<<< NOTE
    GObject-based multi-platform GUI toolkit (v3) (mingw-w64)
mingw64/mingw-w64-x86_64-gtkmm3 3.24.1-1 [installed] <<<<<<<<<<<<<<<<< NOTE
    C++ bindings for gtk3 (mingw-w64)
mingw64/mingw-w64-x86_64-spice-gtk 0.37-1
    GTK3 widget for SPICE clients (mingw-w64)

Where is the problem and how can it be solved?


Solution

  • The include files for the package are not in the default search path. You will need to provide them via the compiler flags -I. As they are many, the easiest way that works for me in MSYS2 is using pkg-config, which will output all needed flags both for compilation and linking:

    g++ $(pkg-config --cflags gtkmm-3.0) -c rngtk1.cpp -o rngtk1.o
    g++ rngtk1.o $(pkg-config --libs gtkmm-3.0) -o rngtk1.exe