gpt4 book ai didi

c++ - 对 `Class::Class()' 的 undefined reference

转载 作者:搜寻专家 更新时间:2023-10-30 23:49:50 26 4
gpt4 key购买 nike

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

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

$ 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​​-config 的最新版本的 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.
}

最佳答案

undefined reference 错误意味着你要么忘了写定义缺失的函数(通过在 .cpp 文件中编写实现),或者您忘记将适当的目标文件或库链接到最终的二进制文件中。

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

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

关于c++ - 对 `Class::Class()' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3506820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com