[英]Error: undefined reference to _imp_***
I am getting errors like error: undefined reference to __imp__ZN12QApplicationC1ERiPPci'
and error: undefined reference to __imp__ZN11QMainWindow11qt_metacastEPKc'
on project build.我在项目构建时收到类似
error: undefined reference to __imp__ZN12QApplicationC1ERiPPci'
error: undefined reference to __imp__ZN11QMainWindow11qt_metacastEPKc'
。 I have tried cleaning and rebuilding but nothing has worked.我尝试过清洁和重建,但没有任何效果。
I have seen many other posts about this error, but no fix methods have worked.我看过很多关于此错误的其他帖子,但没有修复方法有效。 I am new to Qt creator, so I am probably missing something big here, but I made a widget project.
我是 Qt 创建者的新手,所以我可能在这里遗漏了一些重要的东西,但我做了一个小部件项目。 Here are the files:
以下是文件:
main.cpp主.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp主窗口.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主窗口.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
My Qt version 5.10.1, OS is Windows, compiler is MinGW 64.我的 Qt 版本 5.10.1,操作系统是 Windows,编译器是 MinGW 64。
Ok, I fixed it myself, so here's what two things I messed around with: 好的,我自己修复了它,所以这是我搞砸的两件事:
Extending QWidget
instead of QMainWindow
扩展
QWidget
而不是QMainWindow
(Pretty simple) (非常简单)
Checking my kits and using one with the correct version of MinGW - not 64 or 32 bit, it was called something completely different but still had MinGW in the name ;) 检查我的工具包并使用具有正确版本的MinGW的套件-不是64或32位,它的名称完全不同,但名称仍为MinGW;)
The fix is done by installing appropriate versions of the packages you are using.通过安装您正在使用的软件包的适当版本来完成修复。 Some new code techniques can be a hard issue, so installing the right type of package can be hard but required sometimes.
一些新的代码技术可能是一个难题,因此安装正确类型的 package 可能很困难,但有时是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.