User Tools

Site Tools


programming:gtk4

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
programming:gtk4 [2022/03/21 04:49]
nanodano [gtkmm (C++)]
programming:gtk4 [2022/03/21 05:19] (current)
nanodano
Line 128: Line 128:
 You can use [[http://www.gtkmm.org/en/|gtkmm]] to write C++ code instead of C. On their wiki they have  [[https://developer-old.gnome.org/gtkmm-tutorial/stable/|tutorials]] and [[https://developer-old.gnome.org/gtkmm-tutorial/stable/sec-install-unix-and-linux.html.en|build instructions]] for the [[https://download.gnome.org/sources/gtkmm/|source code]]. You can use [[http://www.gtkmm.org/en/|gtkmm]] to write C++ code instead of C. On their wiki they have  [[https://developer-old.gnome.org/gtkmm-tutorial/stable/|tutorials]] and [[https://developer-old.gnome.org/gtkmm-tutorial/stable/sec-install-unix-and-linux.html.en|build instructions]] for the [[https://download.gnome.org/sources/gtkmm/|source code]].
  
-You might some dependencies like glibmm, mm-common, and sigc++-3.0+You might need some other dependencies like
 + 
 +  * sigc++-3.0 
 +  * gtk4 
 +  * glibmm-2.68 
 +  * cairomm-1.16 
 +  * pangomm-2.48 
  
 To build from source: To build from source:
Line 143: Line 150:
 cd libsigc++-3.2.0 cd libsigc++-3.2.0
 cmake . cmake .
 +./autogen.sh --prefix=/usr/local --enable-static
 make make
 sudo make install sudo make install
Line 151: Line 159:
 tar xzf glibmm-2.70.0.tar.gz tar xzf glibmm-2.70.0.tar.gz
 cd glibmm-2.70.0 cd glibmm-2.70.0
-./autogen.sh --prefix=/usr/local+./autogen.sh --prefix=/usr/local --enable-static
 make make
 sudo make install sudo make install
Line 160: Line 168:
 tar xBf cairomm-1.16.1.tar.xz tar xBf cairomm-1.16.1.tar.xz
 cd cairomm-1.16.1 cd cairomm-1.16.1
-./autogen.sh --prefix=/usr/local+./autogen.sh --prefix=/usr/local --enable-static
 make make
 sudo make install sudo make install
Line 169: Line 177:
 tar xzf pangomm-2.50.0.tar.gz tar xzf pangomm-2.50.0.tar.gz
 cd pangomm-2.50.0 cd pangomm-2.50.0
-./autogen.sh --prefix=/usr/local+./autogen.sh --prefix=/usr/local --enable-static
 make make
 sudo make install sudo make install
Line 178: Line 186:
 tar xBf gtkmm-4.6.0.tar.xz tar xBf gtkmm-4.6.0.tar.xz
 cd gtkmm-4.6.0 cd gtkmm-4.6.0
-./autogen.sh --prefix=/usr/local+./autogen.sh --prefix=/usr/local --enable-static
 make make
 sudo make install sudo make install
Line 184: Line 192:
 </code> </code>
  
 +
 +
 +When compiling, use ''-std=c++20'' flag. When running, you may need to set LD_LIBRARY_PATH if you installed to a special prefix. Maybe able to add ''-static'' if you built all libs with ''--enable-static' configuration and a ''.a'' file is in the lib dir.
 +
 +<code bash>
 +# Compile app with gtk4
 +g++ main.cpp `pkg-config gtkmm-4.0 --cflags --libs` -std=c++20
 +
 +# Set path for shared library when running
 +LD_LIBRARY_PATH=/usr/local/lib ./a.out
 +</code>
 +
 +Here is a gtkmm hello world:
 +
 +<code cpp main.cpp>
 +// gtkmm4 example
 +
 +// Compile with:
 +// g++ main.cpp `pkg-config gtkmm-4.0 --cflags --libs` -std=c++20
 +
 +// Run with
 +// LD_LIBRARY_PATH=/usr/local/lib ./a.out
 +#include <gtkmm.h>
 +
 +class MyWindow : public Gtk::Window
 +{
 +public:
 +  MyWindow();
 +};
 +
 +MyWindow::MyWindow()
 +{
 +  set_title("Basic application");
 +  set_default_size(200, 200);
 +}
 +
 +int main(int argc, char* argv[])
 +{
 +  auto app = Gtk::Application::create("org.gtkmm.examples.base");
 +
 +  return app->make_window_and_run<MyWindow>(argc, argv);
 +}
 +</code>
programming/gtk4.1647838172.txt.gz · Last modified: 2022/03/21 04:49 by nanodano