Results 1 to 3 of 3

Thread: Problem trying to compile 'hello world' with gtkmm

  1. #1
    Join Date
    May 2010
    Beans
    5

    Problem trying to compile 'hello world' with gtkmm

    I have been trying to learn how to use gtkmm by following the guide found at:

    http://library.gnome.org/devel/gtkmm-tutorial/ I am trying to compile the hello world program (code found below) that they go through in the tutorial by running

    Code:
    g++ helloworld.cc -o helloworld `pkg-config --cflags --libs gtkmm-2.4`
    When I do this I get the following error:

    Code:
    /usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
    /build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main'
    collect2: ld returned 1 exit status
    I have search all over the place trying to figure out why this is happening, but I keep coming up empty.

    Any assistance would be greatly appreciated!

    File: helloworld.h

    Code:
    #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
    File: main.cc
    Code:
    #include <gtkmm/main.h>
    #include "helloworld.h"
    
    int main (int argc, char *argv[])
    {
      Gtk::Main kit(argc, argv);
    
      HelloWorld helloworld;
      //Shows the window and returns when it is closed.
      Gtk::Main::run(helloworld);
    
      return 0;
    }
    File: helloworld.cc
    Code:
    #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;
    }
    Last edited by lisati; May 6th, 2010 at 10:10 AM. Reason: remove html tags round link

  2. #2
    Join Date
    Mar 2006
    Location
    Eefde, The Netherlands
    Beans
    432
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Problem trying to compile 'hello world' with gtkmm

    You need to compile both helloworld.cc and main.cc into object files and then link them together into an executable (called helloworld in my example):
    Code:
    g++ -c main.cc `pkg-config --cflags --libs gtkmm-2.4`
    g++ -c helloworld.cc `pkg-config --cflags --libs gtkmm-2.4`
    g++ main.o helloworld.o -o helloword `pkg-config --cflags --libs gtkmm-2.4`
    "When in doubt, use brute force."

    -- Ken Thompson

  3. #3
    Join Date
    May 2010
    Beans
    5

    Re: Problem trying to compile 'hello world' with gtkmm

    Oh yeah that makes sense now. Thanks for your help!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •