Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

issues with compiling Hello world program using gtkmm

I am new to C++ and to gtkmm. I am currently trying to compile a tutorial I found online using a window and a button. I am compiling in Ubuntu 12.04. I can compile a single file fine but when I try to compile several files using a Makefile I get an error that I don't understand:

sarah@superawesome:~/gtkexample$ make
g++ -c main.cc
In file included from HelloSarah.h:4:0,
                 from main.cc:1:
/usr/include/gtkmm-3.0/gtkmm/button.h:7:28: fatal error: glibmm/ustring.h: No such file or directory
compilation terminated.
make: *** [main.o] Error 1

I really don't understand the error, I've been searching for hours. I would really appreciate any help or insight into my problem.

These are my 3 files and Makefile:

#ifndef GTKMM_HELLOSARAH_H
#define GTKMM_HELLOSARAH_H

#include <gtkmm-3.0/gtkmm/button.h>
#include <gtkmm/window.h>

class HelloSarah : public Gtk::Window
{

public:
  HelloSarah();
  virtual ~HelloSarah();

protected:
  //Signal handlers:
  void on_button_clicked();

  //Member widgets:
  Gtk::Button m_button;
};

#endif 

and

main.cc

#include "HelloSarah.h"
#include <gtkmm/application.h>

int main (int argc, char *argv[])
{
  Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv,     "org.gtkmm.example");

  HelloSarah hellosarah;

  //Shows the window and returns when it is closed.
  return app->run(hellosarah);
}

and HelloSarah.cc

#include "helloSarah.h"
#include <iostream>

HelloSarah::HelloSarah()
: m_button("Hello Sarah")   // creates a new button with label "HelloSarah".
{
  // 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,
          &HelloSarah::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();
}

HelloSarah::~HelloSarah()
{
}

void HelloSarah::on_button_clicked()
{
  std::cout << "Hello Sarah" << std::endl;
}

and finally my Makefile:

app:            main.o HelloSarah.o
                g++ -o app main.o HelloSarah.o

main.o:         main.cc HelloSarah.h
            g++ -c main.cc

HelloSarah.o:   HelloSarah.cc HelloSarah.h
            g++ -c HelloSarah.cc

clean:      
            rm -f *.o app
like image 243
Sarah Avatar asked Jul 10 '26 08:07

Sarah


2 Answers

The following include statement in your example is not correct. It works only because the file path is relative to the standard /usr/include/ directory, but the include statement in button.h does not, so you get an error message.

#include <gtkmm-3.0/gtkmm/button.h>

You have to tell g++ where the necessary include files and shared objects can be found. You can use the output of pkg-config to do that job.

pkg-config --cflags --libs gtkmm-3.0

The whole g++ command should be something like that.

g++ `pkg-config --cflags --libs gtkmm-3.0` -c HelloSarah.cc

After that you can simply use the include line in gtkmm Hello World.

#include <gtkmm/button.h>
like image 161
Szilárd Pfeiffer Avatar answered Jul 11 '26 22:07

Szilárd Pfeiffer


I had this problem too on Ubuntu.

The solution:

sudo apt-get install libgtkmm-3.0-dev

You can use any version as you need.

like image 36
A1Gard Avatar answered Jul 11 '26 23:07

A1Gard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!