我正在寫一個GTKmm窗口程序;主窗口會創建兩個按鈕,一個用於英文,一個用於中文。用戶可以點擊按鈕以合適的語言顯示不同的窗口。目前,我在初始化主窗口中的多項目容器時遇到問題。它是MainWindowPane類型的一個對象,它繼承了Gtk :: HBox。未定義的引用`Class :: Class()'
當我嘗試做,編譯器會發出以下錯誤:
$ make
g++ -g `pkg-config gtkmm-2.4 --cflags` -c MainWindow.cpp
g++ -g -o QPI_frontend main.o MainWindow.o StartButton.o `pkg-config gtkmm-2.4 --libs`
MainWindow.o: In function `MainWindow':
/home/dmurvihill/Documents/QPI_frontend/MainWindow.cpp:9: undefined reference to `MainWindowPane::MainWindowPane()'
/home/dmurvihill/Documents/QPI_frontend/MainWindow.cpp:9: undefined reference to `MainWindowPane::MainWindowPane()'
collect2: ld returned 1 exit status
make: *** [QPI_frontend] Error 1
我使用的是最新版本的pkg配置的gcc來包含適當的庫。我也是一個java人。
/*
* MAIN_WINDOW.H
* Responsible for creating "slave" RSED windows. Can create English or Chinese
* versions of the demo, and can destroy them all with one click.
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <gtkmm/window.h>
//#include "SlaveWindow.h"
#include "StartButton.h"
#include "MainWindowPane.h"
class MainWindow : public Gtk::Window
{
public:
MainWindow();
private:
MainWindowPane pane;
// std::list<SlaveWindowThread> windows; // Keeps track of all windows that have been created thus far.
void destroyAllWindows(); // Iterates through the linked list and destroys each window.
};
#endif //ifndef MAINWINDOW_H
/*
* MAIN_WINDOW.CPP
*
*/
#include "MainWindow.h"
#include "MainWindowPane.h"
#include "StartButton.h"
MainWindow::MainWindow()// : /*list,*/ pane(/*list*/)
{
pane;
}
void MainWindow::destroyAllWindows()
{
//gtk_widget_destroy(*this);
// TODO: Destroy all the other windows too.
}
/*
* MAIN_WINDOW_PANE.H
*/
#ifndef MAINWINDOWPANE_H
#define MAINWINDOWPANE_H
#include <gtkmm/box.h>
#include <gtkmm/button.h>
//#include "SlaveWindow.h"
#include "StartButton.h"
class MainWindowPane : public Gtk::HBox
{
public:
MainWindowPane(/*&(std::list)*/);
private:
StartButton englishButton; // Used to create a new RSED demo screen.
StartButton chineseButton; // Used to create a new RSED demo in chinese.
// std::list<SlaveWindow> windows; // Keeps track of all windows that have been created thus far.
void destroyAllWindows(); // Iterates through the linked list and destroys each window.
};
#endif //ifndef MAINWINDOWPANE_H
/*
* MAIN_WINDOW.CPP
*
*/
#include "MainWindowPane.h"
#include "StartButton.h"
MainWindowPane::MainWindowPane(/*&(std::list)*/) :
englishButton(StartButton::ENGLISH/*,&(std::list)*/),
chineseButton(StartButton::CHINESE/*,&(std::list)*/)
{
pack_start(englishButton);
englishButton.show();
pack_start(chineseButton);
chineseButton.show();
}
void MainWindow::destroyAllWindows()
{
//gtk_widget_destroy(*this);
// TODO: Destroy all the other windows too.
}
就是這樣。將源代碼添加到我的生成文件中,並且代碼編譯成功。謝謝! 現在,在運行時調試... – ILikeFood 2010-08-17 21:20:23
@ILikeFood,記得點擊答案旁邊的複選標記,以便接受答案。 – 2010-08-17 21:32:17
啊,謝謝。我也試圖把它投票,但我的想法太新了。 – ILikeFood 2010-08-17 21:51:28