title: Qt - Help Linking Dynamic Library
body: <p>I am having a ton of trouble with the simple task of linking a DLL to my Qt project.</p>
  
  <p>My steps:</p>
  
  <ol>
  <li>In Qt, I go to 'File -> New File or Project -> Other Project -> C++ Library'</li>
  <li>Add a <code>calc</code> method to my <strong>mylibrary.h</strong>.</li>
  <li>Implement the <code>calc</code> method in my <strong>mylibrary.cpp</strong>.</li>
  <li>I compile, and I go to the directory where <code>.a</code> and <code>.dll</code> files were created.</li>
  <li>I create a new project: 'File -> New File or Project -> Qt Widget Project -> Qt Gui Application'</li>
  <li>I copy and paste all header files from MyLibrary to <code>C:/Users/Me/includes</code>, as well as <code>MyLibrary.dll</code> and <code>libMyLibrary.a</code> to <code>C:/Users/Me/</code>.</li>
  <li>I then go into my Qt Widget Project's project file (step 5).</li>
  </ol>
  
  <p>I add the include path as well as the DLL path:</p>
  
  <pre><code>INCLUDEPATH += "C:/Users/Me/includes"
  LIBS += "C:/Users/Me/MyLibrary.dll"
  </code></pre>
  
  <p>I then go into my <code>mainwindow.cpp</code>, and put this code:</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  
  #include &lt;QDebug&gt;
  #include "mylibrary.h"
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
  
      MyLibrary myLib;
      qDebug() &lt;&lt; myLib.calc();
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  </code></pre>
  
  <p>And of course, I get undefined errors:</p>
  
  <pre><code>C:\Users\Me\Desktop\TestInternals-Win\..\TestInternals\mainwindow.cpp:15: error: undefined reference to `_imp___ZN13MyLibrary4calcEv'
  
  C:\Users\Me\Desktop\TestInternals-Win\..\TestInternals\mainwindow.cpp:15: error: undefined reference to `_imp___ZN13MyLibrary4calcEv'
  
  :-1: error: collect2: ld returned 1 exit status
  </code></pre>
  
  <hr>
  
  <h2>MyLibrary File Contents</h2>
  
  <p><strong>mylibrary.h</strong> contents:</p>
  
  <pre><code>#ifndef MYLIBRARY_H
  #define MYLIBRARY_H
  
  #include "MyLibrary_global.h"
  
  class MYLIBRARYSHARED_EXPORT MyLibrary{
  public:
      MyLibrary();
      int calc();
  };
  
  #endif // MYLIBRARY_H
  </code></pre>
  
  <p><strong>mylibrary.cpp</strong> contents:</p>
  
  <pre><code>#include "mylibrary.h"
  
  MyLibrary::MyLibrary()
  {
  }
  
  int calc()
  {
      return 5;
  }
  </code></pre>
  
  <p><strong>I have not touched the Qt generated MyLibrary_global.h file</strong></p>
  
  <p>Thanks for any help.</p>