PDA

View Full Version : Link as a dll



bmahf
14th October 2009, 20:17
Hi all,

I am embarrassed to ask, but I cannot seem to work out how to link a project as a dll. I created a new project in Qt Creator 1.2.1, using Qt 4.5.1, and chose for it to be a C++ shared library. I just went ahead and built the library, and found that the resulting shared library had the name libMyProject.a. What I need is a .dll, rather than a .a file. How do I go about getting this. I am used to Visual Studio which would just put out a dll file.

Thanks for your help...

bmahf
14th October 2009, 22:46
Forgot to say that I'm using Qt on Windows Vista. I know, I should be on UNIX, but that's not always possible in this world. :)

Hoping that someone can help me with this probably stupid dilemma. Or was that a dilemma of stupidity.

Bruce

axeljaeger
15th October 2009, 11:44
Please post your .pro-file of the project. It should have something like this in it:


TEMPLATE = lib
CONFIG += shared

If the second line is missing, it will create a static library (.a).

bmahf
15th October 2009, 17:50
Hey axeljaeger, thanks for the info. I didn't have the CONFIG += shared bit. Added that and it now wants to create a dll.

The new issue is that I have a hundred warnings (and some of them errors) such as:

undefined reference to `_imp___ZN10QTabWidgetC1EP7QWidget'

This is happening in 3 different cpp files, and to all of the warning/error instances have to do with Qt files, such as QString, QObject, QTabWidget, QBoxLayout, etc. Some others look like objects/variables that were defined under the covers, like FlagLocation, found in the munged string `_imp___Z13qFlagLocationPKc'. I assume that I have to add some flag to my linker command line call, but not sure what it would be.

My .pro file with your change is now as follows:

------------------MyLib.pro Start--------------------
# -------------------------------------------------
# Project created by QtCreator 2009-10-14T13:19:12
# -------------------------------------------------
TARGET = MyLib
TEMPLATE = lib
CONFIG += qt \
shared # <- added this as suggested
QT += gui \
core \
network \
xml
# DEFINES += BUILD_DLL # <- had this in there before but took it out since you didn't mention it
SOURCES += <list of sources goes here>
HEADERS += <list of headers goes here>
FORMS += src/aboutwindow.ui \
src/mylib.ui
LIBS += -L../lib \
-lidasclient \
INCLUDEPATH += ../../../idasclient/include
OTHER_FILES += src/res/MyLib.rc
RESOURCES += pictures.qrc
RC_FILE = src/res/MyLib.rc
------------------MyLib.pro End--------------------

Again, I looked around for an solution to this before reposting. Thanks again for the information you gave, and for any help you can give with this new issue...
Bruce

bmahf
15th October 2009, 18:16
So I should have given you this information too. The last line that was running when the compile errored out, plus a handful of the first errors tha popped up, are as follows:

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -shared -Wl,--out-implib,debug\libPaulUI.a -o debug\PaulUI.dll object_script.PaulUI.Debug -L"c:\Qt\qt-win-opensource-src-4.5.1\lib" debug\Azigo_res.o -L../lib -lidasclient -lxdi -lftk -lmsvcp80 -lmsvcr80 -lQtXmld -lQtGuid -lQtNetworkd -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCored -lkernel32 -luser32 -lshell32 -luuid -lole32 -ladvapi32 -lws2_32
./debug\passwords.o: In function `ZN9Passwords15initPanelWidgetEv':
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:17: undefined reference to `_imp___ZN10QTabWidgetC1EP7QWidget'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:20: undefined reference to `_imp___ZN7QWidgetC1EPS_6QFlagsIN2Qt10WindowTypeEE '
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:21: undefined reference to `_imp___ZN11QVBoxLayoutC1Ev'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:22: undefined reference to `_imp___ZN11QHBoxLayoutC1Ev'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:23: undefined reference to `_imp___ZN12QTableWidgetC1EiiP7QWidget'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:24: undefined reference to `_imp___ZN11QPushButtonC1ERK7QStringP7QWidget'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:25: undefined reference to `_imp___ZN11QPushButtonC1ERK7QStringP7QWidget'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:26: undefined reference to `_imp___ZN11QPushButtonC1ERK7QStringP7QWidget'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:29: undefined reference to `_imp___ZN7QWidgetC1EPS_6QFlagsIN2Qt10WindowTypeEE '
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:30: undefined reference to `_imp___ZN11QVBoxLayoutC1Ev'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:31: undefined reference to `_imp___ZN11QHBoxLayoutC1Ev'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:32: undefined reference to `_imp___ZN12QTableWidgetC1EiiP7QWidget'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:33: undefined reference to `_imp___ZN11QPushButtonC1ERK7QStringP7QWidget'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:34: undefined reference to `_imp___ZN11QPushButtonC1ERK7QStringP7QWidget'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:37: undefined reference to `_imp___ZN7QWidgetC1EPS_6QFlagsIN2Qt10WindowTypeEE '
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:38: undefined reference to `_imp___ZN11QVBoxLayoutC1Ev'
C:/Users/bruce/Projects/Qt/Azigo/PaulUI/src/passwords.cpp:39: undefined reference to `_imp___ZN11QHBoxLayoutC1Ev'

Hope that gives some more insight...
Bruce

axeljaeger
15th October 2009, 18:38
Every Qt-lib it tries to link against has a d as the last letter. This means it tries to link agains the debug-version of that library. All other libraries are not debug-libraries so I have my doubts that this will work. Anyway, are these debug-versions realy around on your system?

bmahf
15th October 2009, 18:51
Yes, these debug versions:

libQtCored.a
libQtGuid.a
libQtNetworkd.a
libQtXmld.a

are in the same lib directory as the non-debug versions (those with the same exact names except no d at the end).

So you are thinking that I should be linking with debug the whole way? I'm just not sure why that would be different building a dll than a straight .a library. I have built the .a library in debug mode, using the same non-debug versions of the 3 extra libraries being added in, and it built well, and I was able to call it from another driver program and run it, windows widgets and all.

Bruce

axeljaeger
15th October 2009, 18:53
I think you cannot mix debug and non debug libraries on windows.

bmahf
15th October 2009, 19:21
So I changed to a release build, cleaned the project, ran qmake to make sure, and then restarted the build, and got the same exact results. Hmmmm. Definitely stumped here...
Bruce

:eek: