Use Clion on Mac to develop GTK based on CMake

Source: Internet
Author: User
Tags gtk

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.