未定义引用`Class :: Class()' [英] undefined reference to `Class::Class()'

查看:200
本文介绍了未定义引用`Class :: Class()'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个GTKmm窗口程序;主窗口创建两个按钮,一个用于英语,一个用于中文。用户可以点击按钮,以适当的语言打开不同的窗口。目前,我无法初始化主窗口中的多项目容器。它是一个类型MainWindowPane的对象,它继承了Gtk :: HBox。

I am writing a GTKmm window program; the main window creates two buttons, one for English and one for Chinese. The user can click on the button to bring up a different window in the appropriate language. Currently I am having trouble initializing the multiple-item container inside the main window. It is an object of type MainWindowPane, which inherits Gtk::HBox.

当我尝试make时,编译器发出以下错误:

When I try to make, the compiler issues the following error:

$ 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  

我使用最新版本的gcc与pkg-config包括正确的库。我也是一个java人。

I am using the latest version of gcc with pkg-config to include the proper libraries. I am also a java person.

/*
 * 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.
}


推荐答案

未定义的参考错误
忘记编写定义缺少的函数
(通过在 .cpp 文件中编写一个实现),
或者您忘了链接适当的目标文件或库到最终的二进制。

Undefined reference errors mean you either forgot to write define the missing function (by writing an implementation in the .cpp file), or you forgot to link the appropriate object file or library into the final binary.

在这种情况下,这是后来的原因。
您需要在makefile中的链接器命令中包含 MainWindowPane.o

In this case, it's the later reason. You need to include MainWindowPane.o in the linker command in your makefile:

g++  -g -o QPI_frontend main.o MainWindow.o StartButton.o `pkg-config gtkmm-2.4 --libs`
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        you need MainWindowPane.o in here

这篇关于未定义引用`Class :: Class()'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆