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:30]
nanodano
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:
 +
 +
 +<code bash>
 +# Install mm-common
 sudo apt install mm-common sudo apt install mm-common
  
-https://github.com/libsigcplusplus/libsigcplusplus/releases/tag/3.2.0+# Build and install libsigc++3 
 +# https://github.com/libsigcplusplus/libsigcplusplus 
 +wget https://github.com/libsigcplusplus/libsigcplusplus/releases/download/3.2.0/libsigc++-3.2.0.tar.xz 
 +tar xzf libsigc++-3.2.0 
 +cd libsigc++-3.2.0 
 +cmake . 
 +./autogen.sh --prefix=/usr/local --enable-static 
 +make 
 +sudo make install 
 + 
 +# glibmm 
 +# https://gitlab.gnome.org/GNOME/glibmm 
 +wget https://gitlab.gnome.org/GNOME/glibmm/-/archive/2.70.0/glibmm-2.70.0.tar.gz 
 +tar xzf glibmm-2.70.0.tar.gz 
 +cd glibmm-2.70.0 
 +./autogen.sh --prefix=/usr/local --enable-static 
 +make 
 +sudo make install 
 + 
 +# cairomm 
 +# https://www.cairographics.org/releases/ 
 +wget https://www.cairographics.org/releases/cairomm-1.16.1.tar.xz 
 +tar xBf cairomm-1.16.1.tar.xz 
 +cd cairomm-1.16.1 
 +./autogen.sh --prefix=/usr/local --enable-static 
 +make 
 +sudo make install 
 + 
 +# pangomm 
 +# https://gitlab.gnome.org/GNOME/pangomm 
 +wget https://gitlab.gnome.org/GNOME/pangomm/-/archive/2.50.0/pangomm-2.50.0.tar.gz 
 +tar xzf pangomm-2.50.0.tar.gz 
 +cd pangomm-2.50.0 
 +./autogen.sh --prefix=/usr/local --enable-static 
 +make 
 +sudo make install 
 + 
 + 
 +# gtkmm 
 +wget https://download.gnome.org/sources/gtkmm/4.6/gtkmm-4.6.0.tar.xz 
 +tar xBf gtkmm-4.6.0.tar.xz 
 +cd gtkmm-4.6.0 
 +./autogen.sh --prefix=/usr/local --enable-static 
 +make 
 +sudo make install 
 + 
 +</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.1647837038.txt.gz · Last modified: 2022/03/21 04:30 by nanodano