PDA

View Full Version : Linker Error



ankurjain
4th April 2006, 07:56
Hi Guys,
i m here again for ur help ... :)

i've prepared a dll, that provides a table in the main program and the excel like operations (cut,copy,paste ....)

my dll is compiling working fine, but when i use that dll warnings and error come.

please look at the following compiler error :



Compiling...
moc_QGrid.cpp
warning C4273: 'public: static struct QMetaObject const QGrid::staticMetaObject' : inconsistent dll linkage. dllexport assumed.
error C2491: 'QGrid::staticMetaObject' : definition of dllimport static data member not allowed
warning C4273: 'metaObject' : inconsistent dll linkage. dllexport assumed.
warning C4273: 'qt_metacast' : inconsistent dll linkage. dllexport assumed.
warning C4273: 'qt_metacall' : inconsistent dll linkage. dllexport assumed.
Error executing cl.exe.

program.exe - 1 error(s), 4 warning(s)


my pro file for the main project:



################################################## ####################
# Automatically generated by qmake (2.00a) Mon Jan 2 11:42:05 2006
################################################## ####################

TEMPLATE = app
TARGET += program
DEPENDPATH += . ui Uidata
INCLUDEPATH += . ../header/

# Input
HEADERS += xxx.h yyy.h
FORMS += Uidata/xxx.cpp Uidata/yyy.cpp
SOURCES += xxx.cpp yyy.cpp
RESOURCES += Uidata/tds.qrc
QT += xml
UI_DIR = ui
MOC_DIR = moc
OBJECTS_DIR = obj
LIBS = ../dll/release/QGrid.lib


my QGrid.h file is something like this :


#ifndef QGRID_H
#define QGRID_H
#include <QtCore/qglobal.h>
#include <QTableWidget>


#ifdef Q_OS_WIN
# ifdef BUILD_QGRID
# define QGRID_EXPORT Q_DECL_EXPORT
# else
# define QGRID_EXPORT Q_DECL_IMPORT
# endif
#else
# define QGRID_EXPORT
#endif

#include <QAction>

class QGRID_EXPORT QGrid : public QTableWidget
{
Q_OBJECT
public:
QGrid(int c,int r,QWidget *parent = 0);
QGrid(QWidget *parent = 0);

private:
QAction *cutAct;
QAction *copyAct;
QAction *pasteAct;

public slots:
void cut();
void copy();
void paste();
public:
void setUpContextMenu();
void createActions();
};
#endif


i m not getting the cause of the error. i generated the preprocessor files to chk if some problem in macro expansion, but it expands fine .... in dll it expands to __declspec(dllexport) and in the main project it expands to __declspec(dllimport)

when i keep the .cpp and .h file in the main project, this error won't come.

i m using MSVC++ for sompiling the project.

Please help guys, i m stuk for last 1 week in this ...:crying:

jacek
4th April 2006, 14:46
It looks like moc is run on your library headers.

ankurjain
5th April 2006, 05:45
hi,
thanx 4 replying. the problem is solved, the errors are gone, but i don't know y & how ..
i followed the method prescribed by ChristianEhrlicher posted in my other thread, and did like this :



#ifdef BUILD_QGRID
# ifdef Q_CC_MSVC
# define QGRID_EXPORT Q_DECL_EXPORT
# else
# define QGRID_EXPORT Q_DECL_IMPORT
# endif
#else
# define QGRID_EXPORT
#endif


this way it compiles error free.
i earlier used the code (below) :



#ifdef Q_OS_WIN32
# ifdef BUILD_QGRID
# define QGRID_EXPORT Q_DECL_EXPORT
# else
# define QGRID_EXPORT Q_DECL_IMPORT
# endif
#else
# define QGRID_EXPORT
#endif


is there much difference in these codes ? as per logic, both must work fine ....
and ya the error was compiler error not the linker's, but now i can't edit the topic :o

thanx