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.
The *.pro file for the shared lib looks like this:
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"
And the command line from visual studio looks like this:
/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
Here I cannot see any flags that specifies that it is a library and how it is exported.
I then create a global header for the shared library "g_global.h":
#ifndef G_GLOBAL_H
#define G_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(MY_LIBRARY)
# define SHARED_EXPORT_IMPORT Q_DECL_EXPORT
#else
# define SHARED_EXPORT_IMPORT Q_DECL_IMPORT
#endif
#endif
And all my other headerfiles looks like this:
#include "g_global.h"
class SHARED_EXPORT_IMPORT storageProvider : public QObject {
....
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.
The I include the global header, which works. When I include the "storageProvider.h" I get 7 linking errors, here are two of them:
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
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void _thiscall storageProvider::put(class QString const &,class QString const &,class QPointer,int)" (_imp_?put@storageProvider@@QAEXABVQString@@0V?$QPointer@VQIODevice@@@@H@Z) referenced in function "public: void __thiscall FileUploader::uploadNext(void)" (?uploadNext@FileUploader@@QAEXXZ)
I don't know how to be able to include the storageProvider and use it.
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.
Commandline for the main project:
/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
.profile to buildmyapp.exe? - Michael Burr