Re: project with a dll and a testprog (doesn't compile)
Yes. You didn't export anything for the library so the linker didn't need to create a lib.
You have to add Q_DECL_EXPORT to every class you want to export.
Something like:
Code:
//==========================================================//
// //
// Diplomprojekt Calina (platformuebergreifende 3d GUI) //
// //
//==========================================================//
// Autoren: Adam Celarek (diplom_arbeit at xibo at) //
// Patrick Freninger () //
// Sebastian Raggl () //
//==========================================================//
/***************************************************************************
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef CALINAGLWIDGET_H
#define CALINAGLWIDGET_H
#include <QGLWidget>
#include "helper.h"
namespace calina {
/**
* @brief
*
*
*
* @author Adam Celarek <testman@xibo.at>
* @todo Dokumentation von da Klassn.. Wegn Prototyp deadline keine Zeit..
*/
class World;
class
[B
]Q_DECL_EXPORT
[/B
] GLWidget
: public QGLWidget { Q_OBJECT
public:
GLWidget
(WidgetList
& widgetList,
QObject *parent
= 0);
~GLWidget();
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
World* parentWorld() const;
private:
WidgetList& p_widgetList;
};
}
#endif
I added them and got:
Quote:
Generating Code...
cl -c -nologo -Zm300 -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -D
WIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_XML_LIB -DQT_OPENGL_LIB -DQT_GUI_LIB
-DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"c:\Qt\4.3.0rc1\include\QtCore" -I"c:\Qt\4.3
.0rc1\include\QtCore" -I"c:\Qt\4.3.0rc1\include\QtGui" -I"c:\Qt\4.3.0rc1\include
\QtGui" -I"c:\Qt\4.3.0rc1\include\QtOpenGL" -I"c:\Qt\4.3.0rc1\include\QtOpenGL"
-I"c:\Qt\4.3.0rc1\include\QtXml" -I"c:\Qt\4.3.0rc1\include\QtXml" -I"c:\Qt\4.3.0
rc1\include" -I"." -I"c:\Qt\4.3.0rc1\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\
4.3.0rc1\mkspecs\default" -Fodebug\ @D:\DOCUME~1\Marcel\LOCALS~1\Temp\nm783.tmp
moc_glwidget.cpp
moc_graphicsobject.cpp
moc_layout.cpp
moc_widget.cpp
Generating Code...
link /LIBPATH:"c:\Qt\4.3.0rc1\lib" /NOLOGO /DEBUG /DLL /OUT:debug\calina
.dll @D:\DOCUME~1\Marcel\LOCALS~1\Temp\nm784.tmp
Creating library debug\calina.lib and object debug\calina.exp
D:\Documents and Settings\Marcel\Desktop\calina\calina\calina>
Re: project with a dll and a testprog (doesn't compile)
Quote:
Originally Posted by
marcel
Yes. You didn't export anything for the library so the linker didn't need to create a lib.
You have to add Q_DECL_EXPORT to every class you want to export.
Nice catch! however the solution isn't that simple... If Q_DECL_EXPORT is put then the linking of any prog against that lib will most probably fail... Either you already have a kind of config header file which is included by all other headers or you got to create one. Then place something like this in it :
Code:
#ifdef _CALINA_LIB_BUILD_
#if defined(QT_DLL) || defined(QT_SHARED)
#define CALINA_EXPORT Q_DECL_EXPORT
#else
#define CALINA_EXPORT
#endif
#else
#define CALINA_EXPORT Q_DECL_IMPORT
#endif
Then place "DEFINES += CALINA_LIB_BUILD" inside the project file of the dll.
And finally update all headers of the dll, as suggested by marcel but using CALINA_EXPORT instead of Q_DECL_EXPORT...
Re: project with a dll and a testprog (doesn't compile)
It's even simpler, but I skipped this part because I figured he will always build the library alone, so only Q_DECL_EXPORT will be needed.
Just add this to a header and include it in all the exported classes headers:
Code:
#ifndef CALINA_GLOBAL_H
#define CALINA_GLOBAL_H
#include <Qt/qglobal.h>
#ifdef CALINA_LIB
# define CALINA_EXPORT Q_DECL_EXPORT
#else
# define CALINA_EXPORT Q_DECL_IMPORT
#endif
#endif // CALINA_GLOBAL_H
You will have to prepend CALINA_EXPORT instead of Q_DECL_EXPORT.
Also you have to add CALINA_LIB to the list of preprocessor definitions each time you want to build the lib.
Regards
Re: project with a dll and a testprog (doesn't compile)
Quote:
Originally Posted by
marcel
It's even simpler, but I skipped this part because I figured he will always build the library alone, so only Q_DECL_EXPORT will be needed.
Just add this to a header and include it in all the exported classes headers:
I don't recommend making it that simple because in case someone wants to embed the lib in another program (not link) then he will face weird linking errors (either he put the CALINA_BUILD and he is supposed to export symbols but how does an app achieve that? or he forget it and the linker search for exported symbols in an import library that of course does not exist...
Re: project with a dll and a testprog (doesn't compile)
Yes, you have your point too.
I guess he will use whatever he needs from what we've posted, since everything is pretty much covered.
Regards
Re: project with a dll and a testprog (doesn't compile)
Thank you for your answers, I'll try it tomorrow..
I suppose that macro is only needed on windows and vs, right? I had no problems on Linux or on MinGW. How does this work with the gcc, why vs needs the macros and gcc not?
Re: project with a dll and a testprog (doesn't compile)
Quote:
Originally Posted by
aMan
I suppose that macro is only needed on windows and vs, right? I had no problems on Linux or on MinGW. How does this work with the gcc, why vs needs the macros and gcc not?
The macro is not needed on other OS than Windows (I'm sure about Linux but I have not tested under Mac...). As it is needed on one platform it becomes needed on all (I mean putting the CALINA_EXPORT in front of your classes decl). Hopefully Qt is smart enough to leave Q_DECL_EXPORT and Q_DECL_IMPORT empty (while defined) on platforms that do not need them :)
Re: project with a dll and a testprog (doesn't compile)
Thank you, you are greate..
It works now..