QtSerialPort windows static link



  • Hi,
    I use static build Qt4.8 on windows XP. Now I need use QtSerialPort library in my program. So I downloaded this library a compilated it. Every thing seems good (no error).
    So I create new Project with this library, compiling is ok, but linker take me a lot of error. But I included library Qserialport.a to linker.
    I added to serial_port.pro this lines:
    @
    CONFIG += serialport
    LIBS +=-lQtSerialPort
    @

    but linker take this error:
    @
    C:/MinGW/bin/mingw32-make.exe -f Makefile.Debug
    mingw32-make.exe[1]: Entering directory C:/Documents and Settings/pou/Desktop/serial_port' g++ -static -static-libgcc -Wl,-subsystem,windows -o debug\serial_ports.exe debug/main.o debug/mainwindow.o debug/text_porting.o debug/moc_mainwindow.o debug/moc_text_porting.o -L"z:\qt-static\QtSources\4.8.1\lib" -lmingw32 -lqtmaind -lQtSerialPortd -lQtSerialPort -lQtGuid -lsetupapi -lQtCore -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCored -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 mingw32-make.exe[1]: Leaving directoryC:/Documents and Settings/pou/Desktop/serial_port'
    z:\qt-static\QtSources\4.8.1\lib\libQtCored.a(qcoreapplication.o): In function ZN23QCoreApplicationPrivate13checkInstanceEPKc': Z:\qt-static\QtSources\4.8.1\src\corelib/kernel/qcoreapplication.cpp:213: multiple definition ofQCoreApplicationPrivate::checkInstance(char const*)'
    z:\qt-static\QtSources\4.8.1\lib\libQtCore.a(qcoreapplication.o):qcoreapplication.cpp:(.text+0x480): first defined here
    z:\qt-static\QtSources\4.8.1\lib\libQtCored.a(qcoreapplication.o): In function Z32qt_register_signal_spy_callbacksRK21QSignalSpyCallbackSet': Z:\qt-static\QtSources\4.8.1\src\corelib/kernel/qcoreapplication.cpp:225: multiple definition ofqt_register_signal_spy_callbacks(QSignalSpyCallbackSet const&)'
    z:\qt-static\QtSources\4.8.1\lib\libQtCore.a(qcoreapplication.o):qcoreapplication.cpp:(.text+0x4b0): first defined here
    z:\qt-static\QtSources\4.8.1\lib\libQtCored.a(qcoreapplication.o): In function `qt_startup_hook':
    @

    Thank for answer!



  • You can statically linked by other way:

    1. Comment in "qserialportglobal.h" for macro Q_DECL_IMPORT

    @
    #ifndef QT_STATIC

    if defined(QT_BUILD_SERIALPORT_LIB)

    define Q_SERIALPORT_EXPORT // Q_DECL_EXPORT

    else

    define Q_SERIALPORT_EXPORT // Q_DECL_IMPORT

    endif

    #else

    define Q_SERIALPORT_EXPORT

    #endif
    @

    1. Add direcrtly "serialport-lib.pri" to your project file *.pro:

    @
    include(<patch/to/pri>/serialport-lib.pri)
    @



  • Thank you for answer!
    Ok i comment this macro and add serialport-lib.pri to my project, now it send this error:
    @
    serialport-lib.pri:44:6: error: invalid preprocessing directive #MMP_RULES
    serialport-lib.pri:52:7: error: invalid preprocessing directive #FIXME
    serialport-lib.pri:53:6: error: invalid preprocessing directive #INCLUDEPATH

    serialport-lib.pri:1:1: error: 'INCLUDEPATH' does not name a type
    serialport-lib.pri:12:1: error: 'PUBLIC_HEADERS' does not name a type
    serialport-lib.pri:42:1: error: 'symbian' does not name a type
    serialport-lib.pri:66:1: error: 'unix' does not name a type
    serialport-lib.pri:87:1: error: 'HEADERS' does not name a type
    @

    Thank for answer! Jan Opravil


  • Lifetime Qt Champion

    Hi,
    Looks like you included serialport-lib.pri in a header, that's wrong, you have to include it in your project pro file.



  • UPD:

    1. Need comment only for Q_DECL_IMPORT macro in “qserialportglobal.h”:
      @
      ...

    else

    define Q_SERIALPORT_EXPORT //Q_DECL_IMPORT

    endif

    ...
    @

    1. Need to fix some compilation errors like:

    bq. E:\git\ng\123\qtserialport\src\serialport\qserialport.h:48: error: QtSerialPort/qserialportglobal.h: No such file or directory

    Just rename includes from:

    @
    #include <QtSerialPort/qserialportglobal.h>
    @

    to

    @
    #include <qserialportglobal.h>
    @

    and so forth...

    PS: This library is designed as a dynamic. Nobody checked and nobody build it as statically. So any problems related with the static building and linking - please resolve yourself.



  • It still not work for me…(some compiler error)
    But thank!! and i accept this:
    “So any problems related with the static building and linking – please resolve yourself.”
    Now i link this library dynamic and it work.



  • @SGaist How to configure Qserialport static to Qt4.8 in ubuntu12.04


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Unless you really need it as a separated module, do as @kuzulis suggested: include the serialport-lib.pri file in your .pro file


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.