Prerequisite: Installed Gcc,make,cmake, clion,g++ and other gtk unrelated things
1. Install GTK,
Brew Install GTK +
Brew Install Gtk+3
2. Create a new project
The code is as follows
#include <stdio.h> #include <gtk-3.0/gtk/gtk.h>static void Activate (Gtkapplication *app, Gpointer user_ Data) { gtkwidget *window; window = gtk_application_window_new (app); Gtk_window_set_title (Gtk_window (window), "window"); Gtk_window_set_default_size (window), (Gtk_window); Gtk_widget_show_all (window);} int main (int argc, char **argv) { gtkapplication *app; int status; App = Gtk_application_new ("Org.gtk.example", g_application_flags_none); G_signal_connect (App, "Activate", G_callback (Activate), NULL); Status = G_application_run (G_application (APP), argc, argv); G_object_unref (app); return status;}
At this point you will be prompted not to find the relevant definitions.
The point is to set the CmakeLists.txt, file as follows
Cmake_minimum_required (VERSION 3.12) Project (untitled C) set (Cmake_c_standard one) find_package (pkgconfig required) pkg _check_modules (GTK3 REQUIRED gtk+-3.0) include_directories (${gtk3_include_dirs}) link_directories (${GTK3_LIBRARY_ DIRS}) add_definitions (${gtk3_cflags_other}) add_executable (untitled main.c) target_link_libraries (Untitled ${GTK3_ LIBRARIES})
Where untitled is the project name and MAIN.C is the source file
Compile or not, hint <gtk/gtk.h> not found
Do the following:
Brew Install Pkg-config
Compile again, success
Reference links
Https://developer.gnome.org/gtk3/stable/gtk-getting-started.html
Https://developer.gnome.org/gtk3/stable/gtk-compiling.html
Https://intellij-support.jetbrains.com/hc/en-us/community/posts/205823349-Using-GTK-library-in-CLion
Use Clion on Mac to develop GTK based on CMake