Advertisement
Combreal

Compile_Gtkapp_with_MinGW_and_CMake.txt

Jul 15th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. COMPILATION D'APPLICATION GTK3 SUR WINDOWS AVEC CMAKE/MINGW
  2.  
  3. -----------------------------------------------------------------------------------------------------------------
  4.  
  5. Télécharger et installer CMake
  6. https://cmake.org/files/v3.12/cmake-3.12.0-rc3-win64-x64.msi
  7.  
  8. Télécharger et installer MSYS 1
  9. https://netix.dl.sourceforge.net/project/mingw/MSYS/Base/msys-core/msys-1.0.11/MSYS-1.0.11.exe
  10.  
  11. Télécharger et installer MinGW
  12. https://sourceforge.net/projects/mingw-w64/files/latest/download
  13.  
  14. Télécharger l'exécutable et les 2 librairies au liens suivants :
  15. http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.26-1_win32.zip
  16. http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime_0.18.1.1-2_win32.zip
  17. http://ftp.acc.umu.se/pub/gnome/binaries/win32/glib/2.28/glib_2.28.8-1_win32.zip
  18. Les placer tous dans C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin
  19.  
  20. Télécharger l'archive http://gnuwin32.sourceforge.net/downlinks/libintl.php
  21. et déverser les librairies dans C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\lib
  22.  
  23. Télécharger l'archive du bundle gtk
  24. http://www.tarnyko.net/repo/gtk3_build_system/gtk+-bundle_3.6.4-20130513_win32.zip
  25.  
  26. Rajouter les chemins suivants à la variable d'environement PATH:
  27. C:\Program Files\CMake\bin
  28. C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin
  29. C:\msys\1.0\bin
  30. C:\GTK\bin
  31.  
  32. Créer la varibale d'environement système PKG_CONFIG_PATH
  33. avec pour chemin C:\GTK\lib\pkgconfig
  34.  
  35. Se déconnecter/reconnecter de sa session windows pour appliquer les changements de variables d'environement
  36.  
  37. -----------------------------------------------------------------------------------------------------------------
  38.  
  39. Exemple d'application
  40.  
  41. Créer un dossier testGtk à la racine du disque C:\
  42.  
  43. Enregistrer la source suivante au format .cpp dans le dossier testGtk
  44.  
  45. ----------------------------------------------
  46. #include <gtk/gtk.h>
  47.  
  48. int main (int argc, char **argv)
  49. {
  50. GtkWidget *window;
  51. gtk_init (&argc, &argv);
  52.  
  53. window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  54. gtk_window_set_title (GTK_WINDOW (window), "Hello world !");
  55. g_signal_connect (G_OBJECT (window), "destroy", gtk_main_quit, NULL);
  56.  
  57. gtk_widget_show_all (window);
  58. gtk_main ();
  59.  
  60. return 0;
  61. }
  62. ----------------------------------------------
  63.  
  64. Et le fichier de compilation suivant avec le nom CMakeLists.txt toujours dans le dossier testGtk
  65.  
  66. ----------------------------------------------
  67. # Set the name and the supported language of the project
  68. PROJECT(testGtk01)
  69. # Set the minimum version of cmake required to build this project
  70. CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
  71.  
  72. # Use the package PkgConfig to detect GTK+ headers/library files
  73. FIND_PACKAGE(PkgConfig REQUIRED)
  74. PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0)
  75.  
  76. # Setup CMake to use GTK+, tell the compiler where to look for headers
  77. # and to the linker where to look for libraries
  78. INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS})
  79. LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS})
  80.  
  81. # Add other flags to the compiler
  82. ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER})
  83.  
  84. # Add an executable compiled from hello.c
  85. ADD_EXECUTABLE(testGtk01 main.cpp)
  86.  
  87. # Link the target to the GTK+ libraries
  88. TARGET_LINK_LIBRARIES(testGtk01 ${GTK3_LIBRARIES})
  89. ----------------------------------------------
  90.  
  91. Ensuite créer un dossier build dans le dossier testGtk
  92.  
  93. Ouvrir un terminal en tant qu'administrateur et se rendre dans c:\testGtk\build et rentrer la commane suivante
  94. cmake .. -G "MSYS Makefiles"
  95. Puis compiler le tout avec mingw32-make
  96.  
  97. Enfin placer toute les librairies dynamique présente dans le dossier
  98. \bin de l'installation GTK à côté de l'éxecutable fraichement généré
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement