PDA

View Full Version : project with a dll and a testprog (doesn't compile)



aMan
1st July 2007, 23:26
Hi, i have the following structure in my project:
tester/tester.pro
tester/tester.cpp
calina/widget.h
calina/widget.cpp
calina/calina.pro
main.pro

main.pro

SUBDIRS += calina \
tester
TEMPLATE = subdirs
CONFIG += warn_on \
qt \
thread


calina.pro

TEMPLATE = lib

CONFIG += dll \
debug \
opengl \
x11
CONFIG -= release \
stl \
thread
QT += xml \
opengl
TARGET = ../bin/calina

HEADERS += widget.h

SOURCES += widget.cpp



tester.pro

TEMPLATE = app

CONFIG -= release \
stl \
thread
CONFIG += debug \
opengl
QT += xml \
opengl
INCLUDEPATH += ../calina

LIBS += -L../calina \
-l../bin/calina
TARGETDEPS += ../calina/lib../bin/calina.so

SOURCES += tester.cpp


tester.cpp

#include "widget.h"

int main(int argc, char *argv[])
{

calina::Widget widget;
widget.doSomething();

return 0;
}

but if i try to compile it, i get the followin error


## no error, the lib is compiled and then moved to /bin/libcalina.so.1.0.0
make[1]: Leaving directory `/home/damdam/Documents/projekte/dipl_arb/source/calina'
cd tester && /usr/bin/qmake tester.pro -unix -o Makefile
cd tester && make -f Makefile
make[1]: Entering directory `/home/damdam/Documents/projekte/dipl_arb/source/tester'
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_XML_LIB -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include/QtOpenGL -I/usr/include/QtOpenGL -I/usr/include/QtXml -I/usr/include/QtXml -I/usr/include -I../calina -I/usr/X11R6/include -I. -I. -o tester.o tester.cpp
tester.cpp:33: warning: unused parameter ‘argc’
tester.cpp:33: warning: unused parameter ‘argv’
make[1]: *** Keine Regel vorhanden, um das Target »../calina/lib../bin/calina.so«,
benötigt von »tester«, zu erstellen. Schluss.
//make[1]: *** No rule to create target >>../calina/lib.......s<<
// needed by >>teser<<
make[1]: Leaving directory `/home/damdam/Documents/projekte/dipl_arb/source/tester'
make: *** [sub-tester-make_default] Fehler 2
// .. error 2

Can you pleas help me?

fullmetalcoder
2nd July 2007, 08:38
Try this :

calina.pro :


TEMPLATE = lib
CONFIG += dll debug
CONFIG -= thread stl release
DESTDIR = ../bin
QT += xml opengl
TARGET = calina
HEADERS += widget.h
SOURCES += widget.cpp


tester.pro :


TEMPLATE = app
CONFIG += debug
CONFIG -= thread stl release
QT += xml opengl
INCLUDEPATH += ../calina
LIBS += -L../bin -lcalina
SOURCES += tester.cpp

aMan
2nd July 2007, 22:55
Thank you, it compiles fine now. But when i try to execute it, i get the following error:

./tester/tester: error while loading shared libraries: libcalina.so.1: cannot open shared object file: No such file or directory

The lib is in
./bin/libcalina.so
./bin/libcalina.so.1
./bin/libcalina.so.1.0
./bin/libcalina.so.1.0.0

The exe file
./tester/tester

The same, if both the .so files and the tester (bin/exe) are in the same dir..

lld on the tester (exe) shows


linux-gate.so.1 => (0xffffe000)
libcalina.so.1 => not found
libQtXml.so.4 => /usr/lib/libQtXml.so.4 (0xb7f12000)
...


I know whats wrong, but i don't know, how to solve it..

jacek
2nd July 2007, 23:33
./tester/tester: error while loading shared libraries: libcalina.so.1: cannot open shared object file: No such file or directory
There are two solutions. Either you have to edit your /etc/ld.so.conf (or /etc/ls.so.conf.d/something) and run ldconfig as root or make LD_LIBRARY_PATH environment variable point to a directory where the library is.

aMan
3rd July 2007, 11:39
thank you, it works..

aMan
22nd July 2007, 16:53
Hi,
I have still the same pro files, as posted above by fullmetalcoder, but now i'm on windows with vs2005.

The lib is compiled fine and a dll is created. But when it comes to compile the tester program, i get an error like this (translated from german):

link /LIBPATH:"c:\qt\lib" /NOLOGO /DEBUG /SUBSYSTEM:WINDOWS /incremental:no /OUT:"..\bin\tester.exe" @C:\DOKUME~1\damdam\LOKALE~1\Temp\nm817.tmp
LINK : fatal error LNK1181: Input file "calina.lib" couldn't be opened.
.
NMAKE : fatal error U1077: ""C:\Programme\Microsoft Visual Studio 8\VC\BIN\link.EXE"": Return-Code "0x49d"
Stop.
NMAKE : fatal error U1077: ""C:\Programme\Microsoft Visual Studio 8\VC\BIN\nmake.exe"": Return-Code "0x2"
Stop.
NMAKE : fatal error U1077: "cd": Return-Code "0x2"
Stop.


I do compiling with qmake nmake and nothing else. Please help me..

marcel
22nd July 2007, 17:04
Open the project properties and under Linker look at:
General, and see if you have the directory of the lib file listed in "Additional library directories". If not, add it there.
Input, at "Additional Dependencies" and see if you have "calina.lib" listed there. Also, if it isn't there, add it yourself.
EDIT: Well yes, as I can see from your post, you don't meet the conditions for the first point in the solution I have suggested.
So do this, and see if you get any other errors. You shouldn't.

Regards

aMan
22nd July 2007, 18:58
I'm compiling on the command line, so I don't have a project file (only makefiles) and cannot open vs. And I don't have an lib file too (should have mentioned that), because I want dynamic linking..

There should be an option in the pro file for fixing that, but i don't know it (it has to be in the pro file, because it must be platform independant..)

marcel
22nd July 2007, 19:08
But that lib is just the import library used by the linker to link your application to the dll.
So, even if you link dynamically, you will still need a ".lib" to map the functions in your program's import address table to the dll library.

Try with DEPENDPATH qmake variable and set it to the path of the additional dependencies directories( your library).


Regards

aMan
23rd July 2007, 17:52
So how can i get the lib file?

I've tried compiling the lib statically and a calina.lib was created, but the result of compiling the tester was static too.

I've looked into the qt/lib directory. For instance QtGui has 9 files:
QtGui4.dll
QtGui4.exp
QtGui4.lib
QtGui.prl

QtGuid4.dll
QtGuid4.exp
QtGuid4.lib
QtGuid4.pdb
QtGuid.prl

I assume the d in the second list stands for debug, because there is also a pdb file (program debug file from vs). But there are still 4 files for one lib, in my project there is only one (calina.dll) created.

marcel
23rd July 2007, 18:03
It will be generated automatically...
It is by default placed in Debug or Release, depending on which target you compile/.

Regards

aMan
23rd July 2007, 20:38
They aren't. In the debug/releas folders are only the moc_blabla.cpp, blabla.obj and calina.intermediate.manifest files.

fullmetalcoder
23rd July 2007, 21:11
check out your destdir... the .lib (and maybe .exp whatsoever...) should be in the same dir as the .dll unless they fail to be created which you would see when compiling the lib.

aMan
24th July 2007, 17:36
I've looked into all directories, I've even tried to remove the target and destdir variables, but nmake always creates only the dll..

Maybe I could post the project as an zip file and you look into it (if that isn't too much work)?

fullmetalcoder
24th July 2007, 17:42
can't you send us the very last lines of compilation output? Those which would inform us of the linking process... If I remember well, under Windows, a missing symbol (e.g. a function defined but not implemented) can prevent the import library from being created...

aMan
24th July 2007, 19:48
compiling, compiling blabla...
cl -c -nologo -Zm200 -GS -O2 -MD -DNDEBUG -GR -EHsc -W3 -DUNICODE -DQT_L
ARGEFILE_SUPPORT -DWIN32 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
-DQT_THREAD_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_XML_LIB -DQT_OPENGL_LIB -DQT_GUI
_LIB -DQT_CORE_LIB -I"c:\qt\include\QtCore" -I"c:\qt\include\QtCore" -I"c:\qt\in
clude\QtGui" -I"c:\qt\include\QtGui" -I"c:\qt\include\QtOpenGL" -I"c:\qt\include
\QtOpenGL" -I"c:\qt\include\QtXml" -I"c:\qt\include\QtXml" -I"c:\qt\include" -I"
c:\qt\include\ActiveQt" -I"release" -I"." -I"c:\qt\mkspecs\win32-msvc2005" -Fore
lease\ @C:\DOKUME~1\damdam\LOKALE~1\Temp\nm2.tmp
moc_widget.cpp
moc_layout.cpp
moc_glwidget.cpp
moc_graphicsobject.cpp
Code is getting generated... //orig german: Code wird generiert..
link /LIBPATH:"c:\qt\lib" /NOLOGO /DLL /MANIFESTFILE:"release\calina.int
ermediate.manifest" /incremental:no /OUT:"..\bin\calina.dll" @C:\DOKUME~1\damdam
\LOKALE~1\Temp\nm3.tmp
mt.exe -nologo -manifest "release\calina.intermediate.manifest" -outputr
esource:..\bin\calina.dll;2


There are some warnings because of converting double to float, but i don't think that should make any difference..

marcel
24th July 2007, 20:12
C:\environments\tests\libtest>nmake

Microsoft (R) Program Maintenance Utility Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

nmake -f Makefile.Debug

Microsoft (R) Program Maintenance Utility Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

cl -c -nologo -Zm300 -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -D
WIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUP
PORT -I"..\..\..\Qt\4.3.0rc1\include\QtCore" -I"..\..\..\Qt\4.3.0rc1\include\QtC
ore" -I"..\..\..\Qt\4.3.0rc1\include\QtGui" -I"..\..\..\Qt\4.3.0rc1\include\QtGu
i" -I"..\..\..\Qt\4.3.0rc1\include" -I"." -I"..\..\..\Qt\4.3.0rc1\include\Active
Qt" -I"debug" -I"." -I"..\..\..\Qt\4.3.0rc1\mkspecs\default" -Fodebug\ @D:\DOCUM
E~1\Marcel\LOCALS~1\Temp\nm76E.tmp
libtest.cpp
libtest.cpp(4) : warning C4273: 'libtest::libtest' : inconsistent dll linkage
libtest.cpp(9) : warning C4273: 'libtest::~libtest' : inconsistent dll linkage
link /LIBPATH:"c:\Qt\4.3.0rc1\lib" /NOLOGO /DEBUG /DLL /OUT:debug\libtes
t.dll @D:\DOCUME~1\Marcel\LOCALS~1\Temp\nm76F.tmp
Creating library debug\libtest.lib and object debug\libtest.exp

C:\environments\tests\libtest>





################################################## ####################
# Automatically generated by qmake (2.01a) Tue Jul 24 22:10:16 2007
################################################## ####################

TEMPLATE = lib
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += libtest.h libtest_global.h
SOURCES += libtest.cpp


That is what you should get.

Regards

aMan
24th July 2007, 20:42
I now have nearly the same pro file (only some more headers and sources), I have even dropped the double->floats and the opengl support.

But the lib files are still not generating..


Edit: I now see, that there is a difference. I have VS 8 (2005, no sp1) and you 7 (afaik 2003). Is that importand?

marcel
24th July 2007, 20:45
Can you post the code for the library?

The problem must lie there.

Regards

aMan
24th July 2007, 20:59
here you are..
and thanks for looking into it..

marcel
24th July 2007, 21:13
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:



//================================================== ========//
// //
// 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 Q_DECL_EXPORT 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:


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>

fullmetalcoder
24th July 2007, 21:26
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 :


#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...

marcel
24th July 2007, 21:30
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:


#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

fullmetalcoder
24th July 2007, 21:35
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...

marcel
24th July 2007, 21:38
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

aMan
24th July 2007, 23:46
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?

fullmetalcoder
25th July 2007, 09:10
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 :)

aMan
25th July 2007, 19:23
Thank you, you are greate..
It works now..