标签:brew eve pack add director ons gtk3 version other
前提:已 安装好gcc,make,cmake, clion,g++等gtk无关东西
1. 安装gtk ,
brew install gtk+
brew install gtk+3
2. 新建一个工程
代码如下
#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(GTK_WINDOW(window), 200, 200); 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; }
这个时候会提示找不到相关的定义。
重点来了,设置CmakeLists.txt,文件如下
cmake_minimum_required(VERSION 3.12) project(untitled C) set(CMAKE_C_STANDARD 11) 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})
其中,untitled 是项目名称, main.c 是源文件
编译还是不好使,提示找不到<gtk/gtk.h>
做如下操作
brew install pkg-config
再次编译,成功
参考链接
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
标签:brew eve pack add director ons gtk3 version other
原文地址:https://www.cnblogs.com/zhangyy3/p/9438371.html