分页: 1 / 1

这个gtkmm演示程序应该怎么编译阿?

发表于 : 2006-05-13 15:38
chosen
是gtkmm的演示程序
#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:
virtual void on_button_clicked();

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

#endif // GTKMM_EXAMPLE_HELLOWORLD_H
#include "helloworld.h"
#include <iostream>

HelloWorld::HelloWorld()
:m_button("Hello World") // creates a new button with the 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. The on_button_clicked() method is 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;
}
#include <gtkmm/main.h>
#include "helloworld.h"

int main (int argc, char *argv[])
{
Gtk::Main kit(argc, argv);

HelloWorld helloworld;
Gtk::Main::run(helloworld); //Shows the window and returns when it is closed.

return 0;
}
运行
g++ main.cc `pkg-config --cflags --libs gtkmm-2.4`
结果出现
/tmp/ccpUPlk4.o: In function `main':
main.cc:(.text+0x3b): undefined reference to `HelloWorld::HelloWorld()'
main.cc:(.text+0x60): undefined reference to `HelloWorld::~HelloWorld()'
main.cc:(.text+0x77): undefined reference to `HelloWorld::~HelloWorld()'
collect2: ld 返回 1
请问是什么地方出的问题?
应该怎么写这种Makefiles呢?

不好意思
学医的
以前是在dev-cpp下面
不会用automake

发表于 : 2006-05-13 18:10
eexpress
makefile不会写。用anjuta,就都有了。autogen, automake,antuconfigure都安装了。anjuta选gtkmm工程,建立一个。都会自动配置好的。

发表于 : 2006-05-13 18:56
chosen
anjuta不认我用的gtkmm 2.4啊

发表于 : 2006-05-13 19:14
eexpress
libgtkmm-2.4-doc - C++ wrappers for GTK+ 2.4 (documentation)

dapper就是2.4的。试试。

发表于 : 2006-05-14 12:49
chosen
问题解决了
原来是编译的时候没有把helloworld.cc加进去
果真是菜啊
bs自己一下

代码: 全选

g++ main.cc helloworld.cc `pkg-config --cflags --libs gtkmm-2.4`

发表于 : 2006-09-11 16:28
ltkun
我也在看gtkmm的文档哈
有机会探讨一下

发表于 : 2007-03-14 11:24
titainium
eclipse不认gtkmm的头文件路径,看起来要自己写makefile,麻烦。 :?

发表于 : 2007-05-21 16:33
antonym55
titainium 写了:eclipse不认gtkmm的头文件路径,看起来要自己写makefile,麻烦。 :?
eclipse是可以认gtkmm的头文件, 不过我是自己写的Makefile(我用eclipse都是自己写Makefile)

我试了一下,如果不自己写的话,会错认为是gtkmm2.0, 而我装的是2.4

自己写Makefile就没这个问题了