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 directoryC:/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 directory
C:/Documents and Settings/pou/Desktop/serial_port'
z:\qt-static\QtSources\4.8.1\lib\libQtCored.a(qcoreapplication.o): In functionZN23QCoreApplicationPrivate13checkInstanceEPKc': Z:\qt-static\QtSources\4.8.1\src\corelib/kernel/qcoreapplication.cpp:213: multiple definition of
QCoreApplicationPrivate::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 functionZ32qt_register_signal_spy_callbacksRK21QSignalSpyCallbackSet': Z:\qt-static\QtSources\4.8.1\src\corelib/kernel/qcoreapplication.cpp:225: multiple definition of
qt_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:
- Comment in "qserialportglobal.h" for macro Q_DECL_IMPORT
@
#ifndef QT_STATICif 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
@- 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 #INCLUDEPATHserialport-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
-
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:
- Need comment only for Q_DECL_IMPORT macro in “qserialportglobal.h”:
@
...
else
define Q_SERIALPORT_EXPORT //Q_DECL_IMPORT
endif
...
@- 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.
- Need comment only for Q_DECL_IMPORT macro in “qserialportglobal.h”:
-
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
-
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