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...