title: Using your own static library in your own Qt application
body: <p>Following the <a href="https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application" rel="nofollow">How to create a library with Qt and use it in an application</a>, I was able to create and use my own shared library in my own Qt app.</p>
  
  <p>Going forward in the tutorial I reached the <a href="https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application#Creating_a_static_library" rel="nofollow">Creating a static library</a> part which I might (or not) succeeded to understand. I was able to build <code>libtest.a</code> but when trying to use it I got:</p>
  
  <pre><code>15:35:25: Running steps for project loadTestLib...
  15:35:25: Starting: "C:\Qt\Qt5.5.1\5.5\mingw492_32\bin\qmake.exe" C:\Users\User\Downloads\library\client\static\loadTestLib.pro -r -spec win32-g++
  15:35:27: The process "C:\Qt\Qt5.5.1\5.5\mingw492_32\bin\qmake.exe" exited normally.
  15:35:27: Starting: "C:\Qt\Qt5.5.1\Tools\mingw492_32\bin\mingw32-make.exe" 
  C:/Qt/Qt5.5.1/Tools/mingw492_32/bin/mingw32-make -f Makefile.Release
  mingw32-make[1]: Entering directory 'C:/Users/User/Downloads/library/client/static'
  g++ -c -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I. -I. -I.. -I..\testlib -IC:\Qt\Qt5.5.1\5.5\mingw492_32\include -IC:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtWidgets -IC:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtGui -IC:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtANGLE -IC:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore -Irelease -IC:\Qt\Qt5.5.1\5.5\mingw492_32\mkspecs\win32-g++  -o release\main.o ..\main.cpp
  g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\client.exe release/main.o  -lmingw32 -LC:/Qt/Qt5.5.1/5.5/mingw492_32/lib -lqtmain -lshell32 -L../testlib/static/release -ltest -lQt5Widgets -lQt5Gui -lQt5Core 
  release/main.o:main.cpp:(.text+0x2d): undefined reference to `_imp___ZN6WidgetC1Ev'
  Makefile.Release:77: recipe for target 'release\client.exe' failed
  mingw32-make[1]: Leaving directory 'C:/Users/User/Downloads/library/client/static'
  release/main.o:main.cpp:(.text+0x62): undefined reference to `_imp___ZTV6Widget'
  release/main.o:main.cpp:(.text+0xa6): undefined reference to `_imp___ZTV6Widget'
  C:/Qt/Qt5.5.1/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: release/main.o: bad reloc address 0x13 in section `.eh_frame'
  C:/Qt/Qt5.5.1/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
  collect2.exe: error: ld returned 1 exit status
  mingw32-make[1]: *** [release\client.exe] Error 1
  makefile:34: recipe for target 'release' failed
  mingw32-make: *** [release] Error 2
  15:35:32: The process "C:\Qt\Qt5.5.1\Tools\mingw492_32\bin\mingw32-make.exe" exited with code 2.
  Error while building/deploying project loadTestLib (kit: Desktop)
  When executing step "Make"
  15:35:32: Elapsed time: 00:06.
  </code></pre>
  
  <p>Here is the code of the library:</p>
  
  <p>test.pro</p>
  
  <pre><code>QT       += core gui
  
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  
  TEMPLATE = lib
  CONFIG += staticlib
  
  CONFIG(debug, debug|release) {
      DESTDIR = debug
  } else {
      DESTDIR = release
  }
  
  OBJECTS_DIR = $$DESTDIR
  MOC_DIR = $$DESTDIR
  RCC_DIR = $$DESTDIR
  UI_DIR = $$DESTDIR
  
  DEPENDPATH += . ..
  
  INCLUDEPATH += . ..
  
  SOURCES += ../test.cpp
  
  HEADERS += ../test.h
  
  DEFINES += TEST
  </code></pre>
  
  <p>test.h</p>
  
  <pre><code>#include &lt;QtGui&gt;
  
  #if defined TEST
  #define TEST_COMMON_DLLSPEC Q_DECL_EXPORT
  #else
  #define TEST_COMMON_DLLSPEC Q_DECL_IMPORT
  #endif
  
  #include &lt;QWidget&gt;
  
  class TEST_COMMON_DLLSPEC Widget : public QWidget
  {
      Q_OBJECT
  public:
      Widget();
  };
  </code></pre>
  
  <p>test.cpp</p>
  
  <pre><code>#include &lt;QtGui&gt;
  #include "test.h"
  
  Widget::Widget() : QWidget() {}
  </code></pre>
  
  <p>And here is the code for the client app:</p>
  
  <p>loadTestLib.pro</p>
  
  <pre><code>QT       += core gui
  
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  
  TARGET = client
  
  TEMPLATE = app
  
  CONFIG(debug, debug|release) {
      DESTDIR = debug
  } else {
      DESTDIR = release
  }
  
  OBJECTS_DIR = $$DESTDIR
  MOC_DIR = $$DESTDIR
  RCC_DIR = $$DESTDIR
  UI_DIR = $$DESTDIR
  
  SOURCES += ../main.cpp
  
  DEPENDPATH += . ../testlib
  
  INCLUDEPATH += . .. ../testlib
  
  LIBS += -L../testlib/static/release -ltest
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;QApplication&gt;
  
  #include "testlib/test.h"
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
  
      Widget w;
      w.resize(200,200);
      w.show();
  
      return a.exec();
  }
  </code></pre>
  
  <p>What I'm missing?</p>