title: Unresolved external symbols - Qt creator
body: <p>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:</p>
  
  <blockquote>
    <p>main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl
    buildDeck(int,int)" (?buildDeck@@YAXHH@Z) referenced in function _main</p>
  </blockquote>
  
  <p>deck.h</p>
  
  <pre><code>#ifndef DECK_H
  #define DECK_H
  #include &lt;QString&gt;
  
  
  void buildDeck(int deckSize, int jokers);
  
  
  struct card
  {
      QString suit;
      QString color;
      int rank;
  };
  
  #endif // DECK_H
  </code></pre>
  
  <p>deck.cpp</p>
  
  <pre><code>#include"mainwindow.h"
  #include "deck.h"
  
  void buildDeck(int deckSize, int jokers)
  {
      int blackRed = deckSize-=jokers;
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "mainwindow.h"
  #include "deck.h"
  #include &lt;QApplication&gt;
  #include &lt;QPushButton&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
  
      buildDeck(10,20);
  
      return a.exec();
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>All of the files are included in the same project, and stored in the same directory.</p>
  
  <p>Other files:</p>
  
  <p>.pro file</p>
  
  <pre><code>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
  </code></pre>
  
  <p>not sure if you need it, but here's mainwindow.h</p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QPushButton&gt;
  #include &lt;QTextEdit&gt;
  #include &lt;QCheckBox&gt;
  
  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
  </code></pre>