私は、ヘッダーと基本的な概念が欠落して含まれなければならない、私は別のソースファイルから関数の最も単純なを呼び出すしようとすると、私はエラーを取得するために:未解決の外部シンボル - Qtのクリエイター
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl buildDeck(int,int)" ([email protected]@[email protected]) referenced in function _main
デッキ.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の一番下に移動すると、アプリケーションが構築されます。
すべてのファイルが同じプロジェクトに含まれ、同じディレクトリに格納されます。
その他のファイル:ここ
.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だ
#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
コンパイルログの未解決のシンボルは何ですか? – Archie
main.obj:-1:エラー:LNK2019:関数_mainで参照されている未解決の外部シンボル "void __cdecl buildDeck(int、int)"(?buildDeck @@ YAXHH @ Z) – chuckieDub
あなたのコードを試しました。私が得る唯一のことは、未使用のblackRed変数に関する警告です。リンクエラーはありません。ビルドをきれいにして、qmakeを再実行してください。 – Archie