我在项目构建中遇到了像error: undefined reference to __imp__ZN12QApplicationC1ERiPPci'
和error: undefined reference to __imp__ZN11QMainWindow11qt_metacastEPKc'
这样的错误。我已经尝试过清理和重建,但没有任何效果。
我已经看到了许多关于这个错误的其他帖子,但没有修复方法工作.我是新的Qt creator,所以我可能错过了一些大的东西在这里,但我做了一个小部件项目.这里是文件:
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
字符串
主窗口.cpp
#include "mainwindow.h"
#include <QPushButton>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setFixedSize(500,500);
QPushButton myButton;
myButton.setText("Hello world, this is a GUI app!!!");
}
MainWindow::~MainWindow()
{
}
型
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
#endif // MAINWINDOW_H
型
myWindow.pro
#-------------------------------------------------
#
# Project created by QtCreator 2018-03-11T19:52:19
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = myWindow
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
QT += sql #added because I found this to try and solve my problem, doesn't fix
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
型
我的Qt版本5.10.1,操作系统是Windows,编译器是MinGW 64。
3条答案
按热度按时间i5desfxk1#
好吧,我自己修好了,所以这是我搞砸的两件事:
1.扩展
QWidget
而不是QMainWindow
(很简单)
1.检查我的工具包,并使用一个正确版本的MinGW -不是64或32位,它被称为完全不同的东西,但仍然有MinGW的名称;)
mqxuamgl2#
修复是通过安装您正在使用的软件包的适当版本来完成的。一些新的代码技术可能是一个难题,因此安装正确类型的软件包可能很难,但有时是必需的。
6ss1mwsb3#
我最近偶然发现了这个问题,因为我花了很长时间才找到解决方案,所以我决定在这里添加这个答案。
在我的例子中,
undefinded reference to __imp_
是一个指示器,表示我的编译和链接命令中缺少链接选项。要解决这个问题(使用gcc编译器):添加-L(显示要链接的库所在的文件夹)和-l(形式为-llibraryname)。
例如,如果project位于C:/myproject中,并且其中有一个文件夹'libs'。
字符串
我假设有其他编译器的等价物。