title: create and use shared library with qt
body: <p>I am new to the shared library stuff, so I have question about how to create/use a shared library, I am using Qt Creator with qt 5.4.2 with Microsoft Visual C++ 11.0 Compliler.</p>
  
  <p>In my project, I will need to create a dll which call functions from an external library (there are .h, .lib, .dll to use from). To understand how export/import of functions from library work, I tried to create a simple library with one function and use this in another programm first.
  After reading different tutorials, I managed to create the library. In Qt Creator, New Project->Library(C++ Library)->Type(shared library)Name: sharedlib->Modules(QtCore)->Finish. </p>
  
  <p>sharedlib.h:</p>
  
  <pre><code>#ifndef SHAREDLIB_H
  #define SHAREDLIB_H
  
  #include &lt;QtCore/qglobal.h&gt;
  
  #if defined(SHAREDLIB_LIBRARY)
  #  define SHAREDLIBSHARED_EXPORT Q_DECL_EXPORT
  #else
  #  define SHAREDLIBSHARED_EXPORT Q_DECL_IMPORT
  #endif
  
  extern "C" SHAREDLIBSHARED_EXPORT int add(int a, int b);
  
  #endif // SHAREDLIB_H
  </code></pre>
  
  <p>sharedlib.cpp:</p>
  
  <pre><code>#include "sharedlib.h"
  #include &lt;stdio.h&gt;
  
  extern "C" SHAREDLIBSHARED_EXPORT int add(int a, int b)
  {
      return a + b;
  }
  </code></pre>
  
  <p>only added a simple function to add 2 numbers.</p>
  
  <p>after build, I get <code>sharedlib.dll</code> and <code>sharedlib.lib</code> and some other files, (no .a file like in some tutorials, I thought its because I am using microsoft vc compiler which give the .lib file instead).</p>
  
  <p>Now to create a second programm in which I want to use the library:
  New Project->Qt Console Application->Name(loadlib)->Finish, then I copied the <code>sharedlib.lib, sharedlib.h, sharedlib.dll</code> into the loadlib directory.  (do I need them all? and where shall I put them exactly?) 
  According to tutorial, right-click on the project->add library->external library->choose the .lib file inside the loadlib directory, uncheck the Linux and Mac under Platform and choose the Dynamic Linkage.
  this is my loadlib.pro:</p>
  
  <pre><code>QT       += core
  QT       -= gui
  
  TARGET = loadlib
  CONFIG   += console
  CONFIG   -= app_bundle
  
  TEMPLATE = app
  SOURCES += main.cpp
  
  win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -lsharedlib
  else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -lsharedlib
  
  INCLUDEPATH += $$PWD/
  DEPENDPATH += $$PWD/
  </code></pre>
  
  <ol>
  <li>if I put .h and .dll/.lib file in subfolder like loadlib/include and loadlib/libs, it will change to <code>INCLUDEPATH += $$PWD/include DEPENDPATH += $$PWD/include</code> and <code>LIBS += -L$$PWD/libs -lsharedlib</code>, right?</li>
  <li>do I need to copy all 3 files to my loadlib directory?</li>
  <li><p>main.cpp:</p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  #include &lt;QDebug&gt;
  
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
      // simple Debug output to add 7 and 3
  
      return a.exec();
  }
  </code></pre>
  
  <p>how do I actually use the add function here?</p></li>
  </ol>
  
  <p><strong>EDIT</strong>: I changed few things, got rid of the sharedlib_global.h and paste the content into sharedlib.h, and get rid of the class,can I call a function directly without wrap this into a class?</p>