1

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?

rnso
  • 23,686
  • 25
  • 112
  • 234

1 Answers1

1

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
jacob
  • 1,535
  • 1
  • 11
  • 26
  • Yes, it creates an executable, but the exe file does not run since it does not find `libgtkmm-3.0-1.dll`. Where can I find this file? – rnso Sep 23 '19 at 16:16
  • The library `libgtkmm-3.0-1.dll` is in `/mingw64/bin`, which is added automatically to `$PATH` when I start MSYS2 using the "*MSYS2 MinGW 64-bit*" launcher in the Start menu. If you start your MSYS2 shell in some other way, you will need to add `/mingw64/bin` to `$PATH` by hand. – jacob Sep 23 '19 at 16:33
  • I meant executable does not run when transferred to other Windows system. Copying `libgtkmm-3.0-1.dll` with exe file leads to error showing many dll are missing. Do I need to copy all these dll also when distributing my exe file to my friends? Is there any way to statically link all needed dll files with the exe file? – rnso Sep 23 '19 at 16:53
  • Yes, I believe that the most common approach is to bundle those DLLs with your application, but you may also need other files. Gtk+ is big. This seems related: https://stackoverflow.com/questions/49092784/how-to-distribute-a-gtk-application-on-windows – jacob Sep 23 '19 at 18:10