无法解析的外部符号-Qt创建者 [英] Unresolved external symbols - Qt creator
问题描述
我必须缺少包含标头的基本概念,因为我尝试从单独的源文件中调用最简单的函数时,都会收到错误消息:
I must be missing a basic concept with headers and includes because when I attempt to call even the simplest of a function from a separate source file I get an error:
main.obj:-1:错误:LNK2019:未解析的外部符号 void __cdecl
buildDeck(int,int)(?buildDeck @@ YAXHH @ Z)在函数_main <中引用/ p>
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl buildDeck(int,int)" (?buildDeck@@YAXHH@Z) referenced in function _main
deck.h
#ifndef DECK_H
#define DECK_H
#include <QString>
void buildDeck(int deckSize, int jokers);
struct card
{
QString suit;
QString color;
int rank;
};
#endif // DECK_H
deck.cpp
#include"mainwindow.h"
#include "deck.h"
void buildDeck(int deckSize, int jokers)
{
int blackRed = deckSize-=jokers;
}
main.cpp
#include "mainwindow.h"
#include "deck.h"
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
buildDeck(10,20);
return a.exec();
}
这给我一个错误。但是,如果我将功能定义从deck.cpp移到main.cpp的底部,则将构建应用程序。
And this gives me an error. However, If I move the function definition from deck.cpp to the bottom of main.cpp, then the application will build.
所有文件都包含在同一文件中项目,并存储在同一目录中。
All of the files are included in the same project, and stored in the same directory.
其他文件:
.pro文件
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = carddeck
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
deck.cpp
HEADERS += mainwindow.h \
deck.h
FORMS += mainwindow.ui
不确定是否需要它,但这是mainwindow.h
not sure if you need it, but here's mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QTextEdit>
#include <QCheckBox>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void runButtonClicked();
private:
Ui::MainWindow *ui;
QPushButton *runButton;
QTextEdit * runText;
QCheckBox * betHearts;
QCheckBox * betDiamonds ;
QCheckBox * betClubs;
QCheckBox * betSpades ;
QCheckBox * betFlush ;
QCheckBox * betAllRed;
QCheckBox * betAllBlack ;
};
#endif // MAINWINDOW_H
推荐答案
编辑.pro文件时,似乎没有重新生成Makefile。
运行qmake,然后重试。
您还可以检查deck.cpp是否已编译;在构建目录中有一个deck.o吗?
It looks like the Makefile was not regenerated when you edited the .pro file. Run qmake and try again. You could also check if the deck.cpp is compiled or not; is there a deck.o in the build directory ?
这篇关于无法解析的外部符号-Qt创建者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!