Hi! I'm having trouble compiling a very simple gtkmm application. I'm new to gtkmm. I have a class named HelloWorld. It is a window with a button. There are 3 files: helloworld.h, helloworld.cc, main.cc. I can't seem to compile helloworld.cc. Here's how I tried to compile it (not linking yet):
g++ -o helloworld.o -c helloworld.cc `pkg-config gtkmm-2.4 --cflags`
I get this message:
helloworld.cc:6: error: `Helloworld' has not been declared
helloworld.cc:7: error: ISO C++ forbids declaration of `Helloworld' with no type
helloworld.cc: In function `int Helloworld()':
helloworld.cc:7: error: only constructors take base initializers
helloworld.cc:9: error: `set_border_width' undeclared (first use this function)
helloworld.cc:9: error: (Each undeclared identifier is reported only once for each function it appears in.)
helloworld.cc:10: error: `m_button' undeclared (first use this function)
helloworld.cc:10: error: invalid use of `this' in non-member function
helloworld.h:13: error: `virtual void HelloWorld::on_button_clicked()' is protected
helloworld.cc:10: error: within this context
helloworld.cc:11: error: `add' undeclared (first use this function)
Here's my code.
helloworld.h
Code:
#include <gtkmm/button.h>
#include <gtkmm/window.h>
using namespace Gtk;
class HelloWorld : public Gtk::Window
{
public:
HelloWorld();
virtual ~HelloWorld();
protected:
virtual void on_button_clicked();
Button m_button;
};
helloworld.cc
Code:
#include "helloworld.h"
#include <iostream>
using namespace std;
Helloworld::Helloworld()
: m_button( "Hello World" )
{
set_border_width( 10 );
m_button.signal_clicked().connect( sigc::mem_fun( *this, &HelloWorld::on_button_clicked ));
add( m_button );
m_button.show();
}
HelloWorld::~HelloWorld()
{
}
void HelloWorld::on_button_clicked()
{
cout << "Hello World" << endl;
}
main.cc
Code:
#include <gtkmm/main.h>
#include "helloworld.h"
using namespace Gtk;
int main( int argc, char** argv )
{
Main kit( argc, argv );
HelloWorld helloworld;
Main::run( helloworld );
return 0;
}
Is there something wrong with the code or with how I compiled it? I'm sure I installed gtkmm properly. I can compile and run if everything was in one big file, not separated into headers and cc's anymore.