在我的QT项目中添加了一个类并对其进行了实例化后,发生了一个链接器错误。
Undefined symbols for architecture x86_64:
"Main::Main(QWidget*)", referenced from:
Application::Application(int, char**) in Application.o
文件结构如下所示:
src/
Widgets/
Main.hpp
Main.cpp
Application.hpp
Application.cpp
main.cpp
Main.hpp
的内容:
class Main : public QMainWindow
{
Q_OBJECT
public:
explicit Main(QWidget* parent = 0);
}
Main.cpp
,其定义显然无法找到:
Main::Main(QWidget* parent) : QMainWindow(parent)
{
}
它在Application.cpp
:
#include "Widgets/Main.hpp"
...
QMainWindow* window_main = new Main;
window_main->show();
.pro
文件的一部分:
HEADERS += \
src/Application.hpp \
src/Widgets/Main.hpp
SOURCES += \
main.cpp \
src/Application.cpp \
src/Widgets/Main.cpp
INCLUDEPATH += \
src \
src/Widgets
为什么会出现此错误?明确的定义就在那里。