gtkmm依赖特别低,只须要brew下载几十M的lib就完成了开发环境依赖的安装,比安装动则20+G的xcode,简直是光速。html
# 安装gtkmm brew install gtkmm3 # 找到libffi配置文件 find /usr/local/Cellar -name libffi.pc # 把libffi配置文件的目录加入PKG_CONFIG_PATH export PKG_CONFIG_PATH=/usr/local/Cellar//libffi/3.2.1/lib/pkgconfig/ # 查看是否能够获取gtkmm编译参数 pkg-config gtkmm-3.0 --cflags --libs
编写测试代码ios
vim simple.cc #include <gtkmm.h> int main(int argc, char *argv[]) { auto app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base"); Gtk::Window window; window.set_default_size(200, 200); return app->run(window); }
编译c++
g++ -std=c++11 simple.cc -o simple `pkg-config gtkmm-3.0 --cflags --libs`
执行获得的文件vim
./simple
参考
https://developer.gnome.org/g...xcode
mkdir helloworld cd helloworld
vim helloworld.happ
#ifndef GTKMM_EXAMPLE_HELLOWORLD_H #define GTKMM_EXAMPLE_HELLOWORLD_H #include <gtkmm/button.h> #include <gtkmm/window.h> class HelloWorld : public Gtk::Window { public: HelloWorld(); virtual ~HelloWorld(); protected: //Signal handlers: void on_button_clicked(); //Member widgets: Gtk::Button m_button; }; #endif // GTKMM_EXAMPLE_HELLOWORLD_H
vim helloworld.cc测试
#include "helloworld.h" #include <iostream> HelloWorld::HelloWorld() : m_button("Hello World") // creates a new button with label "Hello World". { // Sets the border width of the window. set_border_width(10); // When the button receives the "clicked" signal, it will call the // on_button_clicked() method defined below. m_button.signal_clicked().connect(sigc::mem_fun(*this, &HelloWorld::on_button_clicked)); // This packs the button into the Window (a container). add(m_button); // The final step is to display this newly created widget... m_button.show(); } HelloWorld::~HelloWorld() { } void HelloWorld::on_button_clicked() { std::cout << "Hello World" << std::endl; }
vim main.ccthis
#include "helloworld.h" #include <gtkmm/application.h> int main (int argc, char *argv[]) { auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example"); HelloWorld helloworld; //Shows the window and returns when it is closed. return app->run(helloworld); }
编译spa
g++ -std=c++11 main.cc helloworld.h helloworld.cc `pkg-config gtkmm-3.0 --cflags --libs`
运行./a.out
c++11
gtkmm自带的各类组件(按钮、输入框等)具体看文档,gtkmm自定义组件文档: https://developer.gnome.org/g...