title: Qt Link shared library in Visual Studio 2010
body: <p>I'm working on a project where I have to grab some of the classes and put them into a shared library. The shared library takes care of REST calls and will be used by the main project. </p>
  
  <p>The *.pro file for the shared lib looks like this: </p>
  
  <pre><code>QT       += network
  
  QT       -= gui
  
  TARGET = MyQtFramework
  TEMPLATE = lib
  
  DEFINES += MY_LIBRARY
  
  SOURCES += \
      storageprovider.cpp \
      handler.cpp
  
  HEADERS += \
          myframework_global.h \
      storageprovider.h \
      handler.h 
  
  INCLUDEPATH += "../Shared"
  INCLUDEPATH += "E:\src\Lib\Boost\Current"
  INCLUDEPATH += "E:\src\Lib\CryptLite\Current"
  INCLUDEPATH += "E:\QT"
  
  LIBS += -L"E:\src\Lib\Boost\Current"
  </code></pre>
  
  <p>And the command line from visual studio looks like this: </p>
  
  <blockquote>
    <p>/OUT:"debug\MyQtFramework.dll" /NOLOGO /LIBPATH:"E:\QT\4.8.0\lib" /LIBPATH:"E:\src\Lib\Boost\Current" /LIBPATH:"E:\src\Lib\Boost\Current\lib\debug" /DLL "E:\QT\4.8.0\lib\QtNetworkd4.lib" "E:\QT\4.8.0\lib\QtCored4.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Win32\MyQtFramework.dll.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"PROJECTPATH\debug\MyQtFramework.pdb" /PGD:"PROJECTPATH\debug\MyQtFramework.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE </p>
  </blockquote>
  
  <p>Here I cannot see any flags that specifies that it is a library and how it is exported. </p>
  
  <p>I then create a global header for the shared library "g_global.h": </p>
  
  <pre><code>#ifndef G_GLOBAL_H
  #define G_GLOBAL_H
  
  #include &lt;QtCore/qglobal.h&gt;
  
   #if defined(MY_LIBRARY)
   #  define SHARED_EXPORT_IMPORT Q_DECL_EXPORT
   #else
   #  define SHARED_EXPORT_IMPORT Q_DECL_IMPORT
   #endif
   #endif 
  </code></pre>
  
  <p>And all my other headerfiles looks like this:</p>
  
  <pre><code> #include "g_global.h"
  
   class SHARED_EXPORT_IMPORT storageProvider : public QObject {
       ....
  </code></pre>
  
  <p>So far so good right? This compiles in Visual Studio 2010 and doesn't give any errors. The issue is when I try to use it in my main project. I then INCLUDEPATH and the LIBS whiche the include path points to where the headerfiles for the shared lib are located and the Libs where the *.lib file is. These settings are done on the visual studio property page, not in the *.pro file. </p>
  
  <p>The I include the global header, which works. When I include the "storageProvider.h" I get 7 linking errors, here are two of them: </p>
  
  <blockquote>
    <p>Error 6   error LNK2001: unresolved external symbol "public: virtual int __thiscall storageProvider::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@storageProvider@@UAEHW4Call@QMetaObject@@HPAPAX@Z)   E</p>
    
    <p>Error 2   error LNK2019: unresolved external symbol "__declspec(dllimport) public: void _<em>thiscall storageProvider::put(class QString const &amp;,class QString const &amp;,class QPointer,int)" (</em>_imp_?put@storageProvider@@QAEXABVQString@@0V?$QPointer@VQIODevice@@@@H@Z) referenced in function "public: void __thiscall FileUploader::uploadNext(void)" (?uploadNext@FileUploader@@QAEXXZ) </p>
  </blockquote>
  
  <p>I don't know how to be able to include the storageProvider and use it. </p>
  
  <p>Notice: I renamed all the functions and classes, so if something seems to be wrong, please point it out, but it might just be a misstake I made when I renamed things. </p>
  
  <p>Commandline for the main project: </p>
  
  <blockquote>
    <p>/OUT:"debug\myapp.exe" /NOLOGO /LIBPATH:"E:\QT\4.8.0\lib" /LIBPATH:"e:\QT\4.8.0\lib" /LIBPATH:"E:\src\Lib\Boost\Current" /LIBPATH:"E:\src\Lib\Boost\Current\lib\debug" /LIBPATH:"FILEPATH\MyQtFramework\Debug" "E:\QT\4.8.0\lib\qtmaind.lib" "E:\QT\4.8.0\lib\QtDeclaratived4.lib" "E:\QT\4.8.0\lib\QtGuid4.lib" "E:\QT\4.8.0\lib\QtNetworkd4.lib" "E:\QT\4.8.0\lib\QtCored4.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Win32\myapp.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"FILEPATH\myapp\debug\myapp.pdb" /SUBSYSTEM:WINDOWS /PGD:"FILEPATH\myapp\debug\myapp.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE </p>
  </blockquote>