PDA

View Full Version : How do to add a library to my project?



N3wb
23rd September 2009, 01:22
I need to use a serial port in my program and I found what looks like a really nifty library for Qt called "QExtSerialPort." I downloaded the latest version off sourceforge, built the project, and copied "qextserialportd.dll" over to my project directory. I've never used a DLL before, though, and I'm not sure how to proceed. How do I add it to my project so that I can use the classes inside it?

Thanks for your help!

yogeshgokul
23rd September 2009, 05:20
There is no project settings required for using a DLL in your project.
You have to load library and resolve its functions/symbols.
For that, use QLibrary.

kuzulis
23rd September 2009, 07:18
You can use the library QSerialDevice v 0.1.0 - it is going as static.

But, if you want to use QextSerialPort and do not want to use the class QLibrary - you can connect a dynamic link library *. dll directly in the project file *. pro

faldzip
23rd September 2009, 08:00
Do you have also *.lib (or lib*.a if you use MinGW) file with the same name as this *.dll file?
If yes then you have to link to this .lib (.a) and then just put the .dll in your exec dir.
To link against some library you have to do something like this in your .pro file:


INCLUDEPATH += path/to/library/includes
LIBS += -Lpath/to/lib/or/a/file -lnameofthelibrary

notice -L for the path to library dir and -l to the librtary itself.
next thing is that your dll contains letter "d" at the end of the name (before .dll) and it usually means that it is compiled in debug mode, so use it in debug mode of your application, but try to compile also the release version to link to the release version of your application. then you can do something like this (in .pro file):


CONFIG(debug, debug|release):LIBS += -lnamewithd
CONFIG(release, debug|release):LIBS += -lonlyname

N3wb
29th September 2009, 03:10
Thanks for all of your replies!

I tried your method faldżip, but can't seem to get it to work. Would it be better/more proper to use the QLibrary method that yogeshgokul posted? Either way, it looks like it's going to take me some time to figure this out. I'm just wondering which method I should pursue?

kuzulis
29th September 2009, 05:25
Simply connect the *. dll - not using QLibrary :) IMHO

faldzip
29th September 2009, 07:59
can you show us you *.pro file?

kuzulis
29th September 2009, 08:32
here : http://www.prog.org.ru/topic_8259_0.html

PS: Google translator to help :)

N3wb
2nd October 2009, 04:32
Faldżip, thanks so much for helping. Here's my .pro file:

SOURCES += main.cpp \
mainwindow.cpp \
baction.cpp \
caction.cpp \
arrowbutton.cpp
HEADERS += main.h \
mainwindow.h \
baction.h \
caction.h \
arrowbutton.h
OTHER_FILES += readme.txt

INCLUDEPATH += C:\Users\Nathan\Desktop\qextserialport
LIBS += -LC:\Users\Nathan\Desktop\qextserialport -lqextserialport

CONFIG(debug, debug|release):LIBS += -lqextserialportd
CONFIG(release, debug|release):LIBS += -lqextserialport

The paths I put in there are to this folder: http://www.roboticsguy.com/qextserialport.zip

I'm really over my head here, I've never used DLLs before and have no idea what I'm doing :) I really appreciate your time and any advice you could give me.

faldzip
2nd October 2009, 06:11
LIBS += -LC:\Users\Nathan\Desktop\qextserialport -lqextserialport

CONFIG(debug, debug|release):LIBS += -lqextserialportd
CONFIG(release, debug|release):LIBS += -lqextserialport
in debug version you are linking to both versions of library... so remove -lqextserialport from the first line I pasted.
What does it mean it is not working? What errors you get? Are you using MinGW or VisualStudio?