Setting up developer environment for GTKmm-3.0 and C++
In this post you will learn, how to set up a developer environment for working on graphical user interface (GUI) using C++ programming language, and at the end you will compile an run your first GUI application. To get you started I would recommend Codeblocks, which is an open-source integrated development environment (IDE) for C/C++ programming. You can download Codeblocks at here.After installing Codeblocks you will need to install Gtkmm-3.0-dev which you can find at Gtkmm official website.
As for Linux users you can do the following:
- Debian GNU/Linux:
apt-get install libgtkmm-3.0-dev
- Fedora/RedHat Linux: Use
yum install gtkmm30-docs
to get the runtime, development, and documentation packages. - Gentoo Linux: Get dev-cpp/gtkmm.
- SuSE Linux: Use yast to install gtkmm3-devel.
- Ubuntu Linux:
apt-get install libgtkmm-3.0-dev
Now open Codeblocks and create a new project and select Console Application, choose C++ and name it anything you want.
now add the gtkmm header file:
#include <iostream>
#include <gtkmm-3.0/gtkmm.h>
using namespace std;
int main( int argc, char* argv[])
{
cout<<"Hello world!";
return 0;
}
If the compiler fails to find any dependency header, you can go to settings -> compiler -> search directories and add it. You can download the list here. And under settings -> compiler -> linker settings #other linker options add this two lines:
`pkg-config gtkmm-3.0 --libs`
`pkg-config glibmm-2.4 --libs`
Finally here is your first graphical user interface using C++ and GTKmm-3.0 library:
#include <iostream>
#include <gtkmm-3.0/gtkmm.h>
using namespace std;
int main( int argc, char* argv[])
{
auto myApp = Gtk::Application::create(argc, argv, "org.baktech.Demo");
Gtk::Window mainWindow;
mainWindow.set_size_request(400,400);
mainWindow.set_title("Hello world");
return myApp->run(mainWindow);
}
In the above code sample, we have created an application
auto myApp = Gtk::Application::create(argc, argv, "org.baktech.Demo");
which take terminal input parameters and the application id (e.g "org.baktech.Demo").Next, instantiate Gtk::Window
Gtk::Window mainWindow;
and at the end run the application with your created window as parameter.return myApp->run(mainWindow);
You can download the source code at https://github.com/Bakary-baktech/Gtkmm-3.0-tuto.
No comments:
Post a Comment