ILi*_*ood 2 c++ gtk gcc g++ gtkmm
我正在写一个GTKmm窗口程序; 主窗口创建两个按钮,一个用于英语,一个用于中文.用户可以单击按钮以适当的语言显示不同的窗口.目前我在主窗口内初始化多项容器时遇到问题.它是MainWindowPane类型的对象,它继承了Gtk :: HBox.
当我尝试制作时,编译器发出以下错误:
$ 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
Run Code Online (Sandbox Code Playgroud)
我正在使用最新版本的gcc和pkg-config来包含适当的库.我也是一个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
Run Code Online (Sandbox Code Playgroud)
/*
* 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.
}
Run Code Online (Sandbox Code Playgroud)
/*
* 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
Run Code Online (Sandbox Code Playgroud)
/*
* 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.
}
Run Code Online (Sandbox Code Playgroud)
未定义的引用错误意味着您要么忘记编写定义缺失的函数(通过在.cpp文件中编写实现),要么忘记将相应的对象文件或库链接到最终的二进制文件中.
在这种情况下,这是后来的原因.您需要MainWindowPane.o在makefile中的linker命令中包含:
g++ -g -o QPI_frontend main.o MainWindow.o StartButton.o `pkg-config gtkmm-2.4 --libs`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
you need MainWindowPane.o in here
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9532 次 |
| 最近记录: |