PDA

View Full Version : dll linking



Project25
10th July 2007, 19:15
I am having hard time to find a solution for this linking error:

moc_TableView.obj : error LNK2001: unresolved external symbol "public: static
struct QMetaObject const CModelViewList::staticMetaObject"
(?staticMetaObject@CModelViewList@@2UQMetaObject@@ B)

I am trying to link this against a DLL.

Here's what I have defined for creating DLL


#ifndef QTAP_EXPORT
#define QTAP_EXPORT __declspec( dllexport )
#endif

I have declared QTAP_EXPORT for everyclass for exporting symbols. I start getting this problem once I moved the location of that particular file from one project to another. I have checked the moc files and all are created fine.

thanks,

berzeck
11th July 2007, 05:30
Hi, i had the same problem.
The solution i found is this:
1) In your shared lib project create a .h file like this : ( My librarys name is PulzarLib )

WindowsShit.h

#include <QtCore/qglobal.h>

#ifndef __PULZARLIB_WINDOWSSHIT_H__
#define __PULZARLIB_WINDOWSSHIT_H__

#ifdef Q_WS_WIN // Is the system shitdows ??
#ifdef PULZARLIBEXP // Am i compiling my shared library ?
# define PULZARLIB_EXPORT __declspec(dllexport) // if yes then export my classes
# define prueba1 QString("DEFINIDO").toAscii() // test
#else
# define PULZARLIB_EXPORT __declspec(dllimport) // if not then import the classes
# define prueba1 QString("NENE").toAscii() // test
#endif
#else
#define PULZARLIB_EXPORT // if it is Linux empty this macro
#endif

#endif // __WINDOWSSHIT_H__

2) make sure you pass to the compiler the PULZARLIBEXP flag or edit the Makefile.release in windows and add -DPULZARLIBEXP to de DEFINES variable :

DEFINES = -DPULZARLIBEXP .....

this tells the compilar that we are building our library so we must export our classes

3) Add the defined macro to the definition of the classes that you want to export ( those that your application will use directly ) like this

class PULZARLIB_EXPORT LoginGui : public QDialog

4) in the header files of your application where you will use the library add :

#include <WindowsShit.h>

notice that since PULZARLIBEXP won't be defined in the application then PULZARLIB_EXPORT becomes __declspec(dllimport) , which imports the classes

it seemed that you didnt import your classes if your application

hope that help

PD: sorry bad english :o

Project25
11th July 2007, 07:42
Thanks for reply. I will try tommorow morning. Do I need to add that my header file for instance PulzarLib.h to the project file(.pro) headers. According to error that I am getting is that TableView class in under Project B and CModelViewList class in under Project A. Project A iteslf itself is linking fine but when I try to build project B then I start getting linking error. Because TableView class is inherting CModelListView class/functions from Project A. I defined QTAP_EXPORT __declspec( dllexport ) macro in front of CModelViewList class like

Project A

class QTAP_EXPORT CModelViewList ::public QObject, public....

Project B

class TableView :: public CModelViewList
{
Q_Object
---
}



moc_TableView.obj : error LNK2001: unresolved external symbol "public: static
struct QMetaObject const CModelViewList::staticMetaObject"
(?staticMetaObject@CModelViewList@@2UQMetaObject@@ B)

Thanks,

berzeck
12th July 2007, 07:39
Hi, sorry for the late response.

Addressing your questions :
The header file explained in step 1 must be included just in the lib's .pro file and not in the apps .pro file.

A second consideration : are you using mingw, qmake stack of tools under windows ?

this is important because, for example, the macro Q_WS_WIN is just defined under qmake, if you use visual studio there must be another variables

I strongly reccomend that you use mingw, qmake and qdevelop (IDE) so it is much easier to develop truly multiplataform apps ( at leaste i made my projects under linux and windows )

hope that helps :)