[Qt-interest] how to use static library instead of dll library

Samuel Gaist samuel.gaist at edeltech.ch
Fri Oct 28 09:39:08 CEST 2011


On 28 oct. 2011, at 07:35, Vincent Cai wrote:

> Hi,
>  
>          I have an application project and library project.
>          The library project will generate both static and dll library.
>          And the application will use the library.
>  
>          My question is how to config the application project to use static library or dll library?
>          The code below will always use the dll library, and I don’t know how to make it use static library instead.
>  
> TEMPLATE = app
> CONFIG += console
> QT -= gui
> OBJECTS_DIR = obj
> MOC_DIR = moc
> INCLUDEPATH += ../SRC/qserialdevice
> SOURCES += main.cpp \
> CONFIG(debug, debug|release) {
>     QMAKE_LIBDIR += ../SRC/build/debug
>     LIBS += -lqserialdeviced
>     DESTDIR = debug
>     TARGET = Apped
> } else {
>     QMAKE_LIBDIR += ../SRC/build/release
>     LIBS += -lqserialdevice
>     DESTDIR = release
>     TARGET = App
> }
>  
> Thanks,
> Vincent.
> 
> This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
Hi,
Depending on your platform, if you have both the static and dynamic lib in the same folder with the same base name, the linker will always take the dynamic one.
One way to do this is to have each of them in a separate folder (i.e: shared/libqserialdevice.so and static/libqserialdevice.a) and point LIBS to the correct folder, or rename the static library by appending a suffix to its name (i.e. libqserialdevice_s.a) and use that name when you want to link.

Hope it helps
Samuel


More information about the Qt-interest-old mailing list